Skip to content

Add mock-based unit tests for ExchangeRateProvider#505

Merged
gcomte merged 1 commit intomasterfrom
fix/add-mock-exchange-rate-tests
Mar 30, 2026
Merged

Add mock-based unit tests for ExchangeRateProvider#505
gcomte merged 1 commit intomasterfrom
fix/add-mock-exchange-rate-tests

Conversation

@gcomte
Copy link
Copy Markdown
Owner

@gcomte gcomte commented Mar 30, 2026

Summary

  • Add 5 offline unit tests using a mock ExchangeRateApiConsumer
  • Tests cover: inverse calculation, caching (fetch called once), missing currency panic, zero rate → infinity, multi-currency lookups
  • No network dependency — these run reliably in any environment

Tests cover: correct inverse calculation, caching behavior (fetch_api
called only once), missing currency panic, zero rate producing infinity,
and multi-currency lookups. All run offline without hitting the API.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20c139f9-2207-4137-b4a2-1d5eb76e5f5f

📥 Commits

Reviewing files that changed from the base of the PR and between 0fc0ae0 and 9a19b6c.

📒 Files selected for processing (1)
  • src/fiat_rates/exchange_rate_provider.rs

📝 Walkthrough

Walkthrough

A test module was added to src/fiat_rates/exchange_rate_provider.rs containing a mock implementation of ExchangeRateApiConsumer and unit tests validating ExchangeRateProvider behavior, including caching, rate calculations, and edge cases.

Changes

Cohort / File(s) Summary
Test Module Addition
src/fiat_rates/exchange_rate_provider.rs
Added #[cfg(test)] test module with MockApiConsumer mock and five unit tests covering btc_value return logic, API caching behavior, missing currency handling, zero rate edge cases, and multiple currency support.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Tests hop in with bounds so fine,
Caching logic checked line by line,
Mocks and assertions, all aligned,
No production code redesigned!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding mock-based unit tests for the ExchangeRateProvider class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/add-mock-exchange-rate-tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gcomte gcomte merged commit b514dd2 into master Mar 30, 2026
7 checks passed
@gcomte gcomte deleted the fix/add-mock-exchange-rate-tests branch March 30, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant