feat: add unit tests for BalancesService and enhance wallet limit refresh logic#2689
feat: add unit tests for BalancesService and enhance wallet limit refresh logic#2689
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughReorders an early-return guard in BalancesService.refreshUserWalletLimits so end-trial state updates are applied before returning; adds a new comprehensive test suite validating end-trial and limits-update scenarios for that method. Changes
Sequence Diagram(s)sequenceDiagram
rect rgba(200,200,255,0.5)
participant Caller
participant BalancesService
participant UserWalletRepo
participant TxManager
participant AuthzHttp
participant DeploymentHttp
participant StatsService
end
Caller->>BalancesService: refreshUserWalletLimits(walletId, endTrial?, incomingLimits?)
BalancesService->>UserWalletRepo: fetch wallet
BalancesService->>BalancesService: compute freshLimits (getFreshLimitsUpdate)
alt endTrial provided
BalancesService->>UserWalletRepo: update isTrialing = false (if applicable)
end
alt freshLimits differ from current
BalancesService->>TxManager: begin transaction
BalancesService->>UserWalletRepo: update feeAllowance/deploymentAllowance
BalancesService->>DeploymentHttp: notify/update deployments (conditional)
BalancesService->>AuthzHttp: update authz (conditional)
BalancesService->>StatsService: record metrics
BalancesService->>TxManager: commit
else no updates needed
BalancesService-->>Caller: return (no further updates)
end
BalancesService-->>Caller: return updated wallet state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2689 +/- ##
==========================================
- Coverage 51.77% 50.96% -0.82%
==========================================
Files 1045 1010 -35
Lines 27447 26615 -832
Branches 6340 6245 -95
==========================================
- Hits 14211 13564 -647
+ Misses 12809 12633 -176
+ Partials 427 418 -9
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/api/src/billing/services/balances/balances.service.spec.ts`:
- Around line 70-83: The setup function is currently defined inside a nested
suite—move the entire setup function (the function named setup that constructs
BalancesService, mocks BillingConfig, UserWalletRepository, TxManagerService,
AuthzHttpService, DeploymentHttpService, StatsService and spies on
service.getFreshLimitsUpdate) to the bottom of the root describe block; ensure
it remains an untyped-return helper that accepts a single optional parameter
with inline type { limitsUpdate?: Partial<UserWalletInput> }, returns the
created { service, userWalletRepository } object, and does not introduce shared
state or a declared return type, preserving the jest.spyOn(service,
"getFreshLimitsUpdate").mockResolvedValue(...) behavior.
apps/api/src/billing/services/balances/balances.service.spec.ts
Outdated
Show resolved
Hide resolved
d92a069 to
b1ca190
Compare
Summary by CodeRabbit
Tests
Refactor