Skip to content

test: settings_user_data_cubit + transaction_history_service (+12 tests)#336

Merged
TaprootFreak merged 1 commit into
developfrom
test/userdata-cubit-and-tx-history
May 15, 2026
Merged

test: settings_user_data_cubit + transaction_history_service (+12 tests)#336
TaprootFreak merged 1 commit into
developfrom
test/userdata-cubit-and-tx-history

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

Summary

Stage 12 of the coverage push. Covers the previously-deferred `settings_user_data_cubit` (3-service coordination + Country lookups) and the read-side of `transaction_history_service`.

File under test Test file Cases
`lib/screens/settings_user_data/cubit/settings_user_data_cubit.dart` `test/screens/settings_user_data/settings_user_data_cubit_test.dart` 6
`lib/packages/service/transaction_history_service.dart` (`fetchPendingTransactions` only) `test/packages/service/transaction_history_service_test.dart` 6

What each file covers

  • settings_user_data_cubit: the cubit fans out to `RealUnitWalletService.getWalletStatus` and `DfxKycService.getKycStatus` in parallel, then either falls back to `getUser` (when userData is missing) or runs two more `getCountryBySymbol` lookups. Tests pin:
    • Full Success when userData is present (with nationality + addressCountry country lookups resolved to distinct `Country` instances).
    • `pendingSteps` only contains the three change steps (name/address/phone) that are in `inReview` — other inReview steps (e.g. `contactData`) are ignored.
    • `userData == null` + `getUser` returns mail → `Success(email)`, no country lookups happen.
    • `userData == null` + `getUser` throws → `Success()` with both userData and email null.
    • Failure when `getWalletStatus` throws (the `Future.wait` propagation).
    • Failure when `getCountryBySymbol` throws on a userData with a country code.
  • transaction_history_service.fetchPendingTransactions: no auth token short-circuits to `[]` without any HTTP call (verified via a MockClient that records calls); GET shape with the Bearer JWT to `/v1/transaction/detail`; non-200 returns `[]` (does not throw — intentional UX); filters out `Completed`/`Failed`/`Returned` (`isPending=false` per the enum extension); filters out transactions whose `sourceAccount` / `targetAccount` don't match the current wallet; wallet-match is case-insensitive (covers the lower-casing on both sides).

Notes

Excluded (and why)

  • `transaction_history_service.apiBasedSync` — writes through `TransactionRepository.insertDfxTransaction`/`updateTransaction` and depends on `AppStore.primaryAddress` + `apiConfig.asset.chainId`. Doable but adds repository mock plumbing for a method that's almost entirely orchestration; will be its own focused PR.
  • Buy / sell cubits — still held while fix: keep dashboard buy actions visible #321 (dashboard buy actions) and fix(bitbox): harden multi-page sign and KYC routing #332 (bitbox sign hardening) are open.

Test plan

  • `flutter analyze` on the two new files — clean
  • `flutter test` — 12 / 12 passing locally
  • CI green

Stage 12 of the coverage push.

- settings_user_data_cubit (6): Success when userData is present
  with nationality+addressCountry country lookups; Success
  surfaces pending change steps (filters non-{name/address/phone}
  change steps and non-inReview status); userData=null + getUser
  returns mail → Success(email); userData=null + getUser throws →
  Success() with no email; Failure when getWalletStatus throws;
  Failure when getCountryBySymbol throws
- transaction_history_service (6): fetchPendingTransactions returns []
  without hitting the network when no auth token; GET shape with
  Bearer JWT; returns [] on non-200 (does not throw); filters out
  completed/failed/returned (isPending=false); filters out
  transactions that do not belong to the current wallet; wallet
  match is case-insensitive
@TaprootFreak TaprootFreak marked this pull request as ready for review May 15, 2026 11:47
@TaprootFreak TaprootFreak merged commit 8a59115 into develop May 15, 2026
1 check passed
@TaprootFreak TaprootFreak deleted the test/userdata-cubit-and-tx-history branch May 15, 2026 11:47
TaprootFreak added a commit that referenced this pull request May 15, 2026
)

## Summary
Stage 19 of the coverage push. Closes the previously-deferred
apiBasedSync gap on TransactionHistoryService — kept in a separate file
from \`fetchPendingTransactions\` (#336) to keep the repository mocks
focused on the sync flow.

| Method under test | Test file | Cases |
| --- | --- | --- |
| \`TransactionHistoryService.apiBasedSync\` |
\`test/packages/service/transaction_history_service_sync_test.dart\` | 8
|

## What it covers
- Non-200 on \`/v1/realunit/account/<addr>/history\` short-circuits: no
repository writes (the cubit's early return when AccountHistoryDto is
null).
- Entries whose \`transfer\` field is null are skipped.
- Inserts a plain \`Transaction\` when there is no matching DFX row.
- Inserts a DFX-enriched transaction (\`insertDfxTransaction\`) when
\`/v1/transaction\` has a row whose \`id\` is not null and whose
\`inputTxId\` matches the history hash.
- Existing transactions go through \`updateTransaction\` /
\`updateDfxTransaction\` instead of insert (governed by
\`existsTransaction\`).
- The DFX-row match also accepts \`outputTxId\` — both directions are
pinned.
- DFX rows whose \`id\` is null fall back to the plain-Transaction
insert path.

## Notes
- Both endpoints are fetched via \`Future.wait\`. Reading
\`request.url.path\` lets a single MockClient handler return different
bodies for the two paths.
- The test stubs \`existsTransaction\` to return false by default, then
flips it to true for the update-path tests.

## Test plan
- [x] \`flutter analyze\` on the new file — clean
- [x] \`flutter test\` — 8 / 8 passing locally
- [ ] CI green
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.

1 participant