test_finance_service_balance.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Unit tests for how a balance is reported."""
  2. import pytest
  3. from backend.app.models.settings import Settings
  4. from backend.app.schemas.settings import AppSettings as AppSettingsSchema
  5. from backend.app.services.finance_balance import resolve_configured_currency
  6. class TestConfiguredCurrency:
  7. """#3123: finance is not allowed its own idea of the currency.
  8. Every other surface renders the ``currency`` app setting. Finance answered
  9. from a per-wallet column instead, which three of its four writers filled
  10. with a hardcoded "EUR", so an install configured for AUD reported euros.
  11. The column is gone and this function is what replaced it.
  12. """
  13. @pytest.mark.asyncio
  14. async def test_reads_the_configured_currency(self, db_session):
  15. db_session.add(Settings(key="currency", value="AUD"))
  16. await db_session.commit()
  17. assert await resolve_configured_currency(db_session) == "AUD"
  18. @pytest.mark.asyncio
  19. async def test_falls_back_to_the_app_default_when_unset(self, db_session):
  20. # The app default is USD, which is also what every frontend fallback
  21. # uses. The old finance fallback said EUR, which is how an install
  22. # that never touched the setting still showed euros.
  23. assert await resolve_configured_currency(db_session) == AppSettingsSchema().currency
  24. assert await resolve_configured_currency(db_session) == "USD"
  25. @pytest.mark.asyncio
  26. async def test_an_empty_setting_row_is_not_a_currency(self, db_session):
  27. db_session.add(Settings(key="currency", value=""))
  28. await db_session.commit()
  29. assert await resolve_configured_currency(db_session) == "USD"