Skip to content

feat: add unit tests for BalancesService and enhance wallet limit refresh logic#2689

Merged
baktun14 merged 3 commits intomainfrom
fix/trial-flag
Feb 19, 2026
Merged

feat: add unit tests for BalancesService and enhance wallet limit refresh logic#2689
baktun14 merged 3 commits intomainfrom
fix/trial-flag

Conversation

@baktun14
Copy link
Contributor

@baktun14 baktun14 commented Feb 8, 2026

Summary by CodeRabbit

  • Tests

    • Added comprehensive tests for wallet limit refresh covering trial-ending, unchanged limits, limit changes, and non-trial wallets.
  • Refactor

    • Updated the update flow so trial-end status is applied before deciding to skip further updates, ensuring trial transitions are handled correctly.

@baktun14 baktun14 requested a review from a team as a code owner February 8, 2026 04:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Reorders 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

Cohort / File(s) Summary
Test Suite
apps/api/src/billing/services/balances/balances.service.spec.ts
Adds unit tests for refreshUserWalletLimits covering: end-trial with/without limit changes, limit-only changes, non-trialing wallets, and no-op behavior; introduces a setup helper and stubs getFreshLimitsUpdate.
Service Implementation
apps/api/src/billing/services/balances/balances.service.ts
Moves the early no-update guard to after applying endTrial adjustments so isTrialing can be cleared even when limits remain unchanged.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through lines to flip a flag,

End-trial cleared before the early drag.
Limits checked, small changes wake the night,
Tests now guard each gentle, measured bite.
A tiny rabbit's balance feels just right.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely empty, missing both required sections: 'Why' (rationale/issue references) and 'What' (explanation of changes). Add a description explaining why these changes were made, reference any related issues, and describe what was changed in the PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main changes: adding unit tests for BalancesService and enhancing wallet limit refresh logic.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/trial-flag

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

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.96%. Comparing base (292820f) to head (a282695).
⚠️ Report is 25 commits behind head on main.

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     
Flag Coverage Δ *Carryforward flag
api 76.65% <100.00%> (-0.02%) ⬇️
deploy-web 37.19% <ø> (ø) Carriedforward from 292820f
log-collector ?
notifications 85.56% <ø> (ø) Carriedforward from 292820f
provider-console 81.48% <ø> (ø) Carriedforward from 292820f
provider-proxy 82.41% <ø> (ø) Carriedforward from 292820f
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../src/billing/services/balances/balances.service.ts 75.38% <100.00%> (+1.53%) ⬆️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

stalniy
stalniy previously approved these changes Feb 10, 2026
@baktun14 baktun14 requested a review from ygrishajev February 17, 2026 18:11
@baktun14 baktun14 added this pull request to the merge queue Feb 19, 2026
Merged via the queue into main with commit fd91ace Feb 19, 2026
54 of 55 checks passed
@baktun14 baktun14 deleted the fix/trial-flag branch February 19, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments