Test: Implement E2E: Complete Escrow and Cargo Insurance Flow - #539
Conversation
|
@BigManly4 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! 🚀 |
|
Note on the failing CI run: it fails at the
I have deliberately left these alone rather than bundling unrelated source fixes into a test-scoped PR, and the For what it is worth, the test suite itself is unaffected. Locally, |
Summary
Automates the end-to-end flow of a shipper selecting cargo insurance and completing the XLM escrow payment at checkout.
The repository had escrow lock and payout pieces but no cargo insurance step and no checkout flow to drive, so this PR adds the flow under test alongside the tests. Every external boundary is mocked, so the suite makes no network calls and does not depend on a wallet extension.
Changes
types/insurance.ts(new)InsurancePlan— a coverage product: coverage, premium, optional deductible and a recommended flag. All amounts in XLM.EscrowCheckoutQuote— the priced breakdown: shipment cost, premium, total and the selected plan.EscrowCheckoutParams/EscrowCheckoutReceipt— the payment payload and the on-chain confirmation.successresult unions matching the convention used by the other services here.services/insuranceService.ts(new)getPlans(shipmentId)— fetches the coverage offered for a shipment.payWithEscrow(params)— posts the checkout and returns the escrow receipt. Validates shipment id, wallet address and amount before touching the network.buildCheckoutQuote(shipmentXlm, plan)— pure pricing, so the total displayed to the shipper and the amount submitted on chain come from one source.toStroopPrecision/formatXlm— XLM is divisible to seven decimals, so amounts are rounded to one stroop. This is what stops0.1 + 0.2reaching either the UI or the contract as0.30000000000000004.hooks/useEscrowCheckout.ts(new) — owns step and request state across the three checkout steps, delegating every network call to the service.components/escrow/EscrowInsuranceCheckout.tsx(new) — the flow itself:Headings,
radiogroup,role="alert"androle="status"are used throughout so the tests query the way a user perceives the page rather than by implementation detail.components/escrow/__tests__/EscrowInsuranceCheckout.test.tsx(new) — 21 flow tests.services/__tests__/insuranceService.test.ts(new) — 23 service tests.Mocking strategy
axiosis mocked in the service suite.axios.isAxiosErroris a type guard rather than a request method, so auto-mocking leaves it returningundefined; the suite restores real behaviour explicitly, which is what lets the error-branch assertions actually exercise the axios path.getPlansandpayWithEscrow, keepingbuildCheckoutQuoteandformatXlmreal viajest.requireActual. The totals asserted in the flow tests are therefore the ones production pricing produces, not values restated in the test.Test coverage
Happy path
insurancePlanId: null, and no policy reference on the receipt.Empty states
Edge cases
0.3 XLM.Error handling
Verification
eslintandtsc --noEmitare clean for the added files.The full suite was run against
mainand again with this branch applied. Both runs report 24 failing suites and 71 failing tests; this branch adds 2 passing suites and 44 passing tests and changes no existing failure. Those pre-existing failures are unrelated to this work and are left untouched, including the placeholder at__tests__/features/checkout/checkout-flow.test.tsx, whose component import is still commented out upstream.closes #510