Skip to content

refactor: extract shared stats calculation to src/utils/stats.ts#508

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
AgilityB:Share-calculateStats-logic-with-dummyData
Jun 1, 2026
Merged

refactor: extract shared stats calculation to src/utils/stats.ts#508
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
AgilityB:Share-calculateStats-logic-with-dummyData

Conversation

@AgilityB
Copy link
Copy Markdown

@AgilityB AgilityB commented Jun 1, 2026

refactor: extract shared subscription stats calculation utility

The stats calculation logic was duplicated between subscriptionStore.ts and dummyData.ts, with slightly different implementations — creating a risk of inconsistent results and double the maintenance burden.

Changes

stats.ts
— new shared utility exposing toMonthlyPrice, toYearlyPrice, and calculateSubscriptionStats. Accepts an optional PriceConverter callback so callers can plug in currency conversion without coupling the utility to any service.
subscriptionStore.ts
— replaced ~40 lines of inline reduce logic with a single calculateSubscriptionStats call, passing currencyService.convert as the converter.
dummyData.ts
— getTotalMonthlySpending now delegates to toMonthlyPrice instead of its own switch block.
stats.test.ts
— new tests covering empty/null input, inactive subscription filtering, all billing cycles, currency conversion, category breakdown, and gas spend aggregation.
Testing
npm test -- --testPathPattern="src/utils/tests/stats.test.ts" --no-coverage --watchAll=false

Closes #63

- Add calculateSubscriptionStats, toMonthlyPrice, toYearlyPrice utilities
- Replace duplicated logic in subscriptionStore and dummyData with shared util
- Support optional PriceConverter for currency-aware calculations in store
- Add tests for stats utility covering all billing cycles and edge cases
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@AgilityB Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit ec44ae8 into Smartdevs17:main Jun 1, 2026
1 check passed
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.

🔧 Share calculateStats logic with dummyData

2 participants