refactor: extract shared stats calculation to src/utils/stats.ts#508
Merged
Smartdevs17 merged 1 commit intoJun 1, 2026
Merged
Conversation
- 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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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