Skip to content

test(service): transaction_history_service.apiBasedSync (+8 tests)#342

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

test(service): transaction_history_service.apiBasedSync (+8 tests)#342
TaprootFreak merged 1 commit into
developfrom
test/tx-history-sync

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

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//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

  • `flutter analyze` on the new file — clean
  • `flutter test` — 8 / 8 passing locally
  • CI green

Stage 19 of the coverage push. Covers the previously-deferred
apiBasedSync method (separate test file from fetchPendingTransactions
to keep mocks focused).

- non-200 on /history → no repository writes (early return)
- entries with no transfer are skipped
- inserts a plain Transaction when no matching DFX row exists
- inserts a DFX-enriched transaction when /v1/transaction has a row
  with id matching inputTxId
- existing transactions go through updateTransaction (not insert)
- existing DFX rows go through updateDfxTransaction
- outputTxId match also resolves the DFX record (not just inputTxId)
- DFX rows without an id fall back to the plain-Transaction insert path
@TaprootFreak TaprootFreak marked this pull request as ready for review May 15, 2026 11:48
@TaprootFreak TaprootFreak merged commit 5e64eaa into develop May 15, 2026
1 check passed
@TaprootFreak TaprootFreak deleted the test/tx-history-sync branch May 15, 2026 11:48
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