test(#319, #320): add comprehensive test coverage for api.ts and contract.ts - #1
Open
Uchechukwu-Ekezie wants to merge 1 commit into
Open
test(#319, #320): add comprehensive test coverage for api.ts and contract.ts#1Uchechukwu-Ekezie wants to merge 1 commit into
Uchechukwu-Ekezie wants to merge 1 commit into
Conversation
…sive test coverage for api.ts and contract.ts Implements test suites for api.ts (issue Parashield-Protocol#319) and contract.ts (issue Parashield-Protocol#320): api.test.ts: - Tests unwrap() throws ApiError on success:false even with HTTP 200 (issue Parashield-Protocol#198) - Tests withRetry() behavior: retries 5xx errors with exponential backoff, throws immediately on 4xx - Tests auth interceptor adds Bearer token when session exists - Tests auth error handler called on 401 responses - Tests endpoint behavior for 404 handling in fetchClaim() and fetchOracleReading() contract.test.ts: - Tests buildBuyPolicyTx() encodes oracle key as {type: 'string'} not {type: 'symbol'} (issue Parashield-Protocol#194 regression) - Tests simulateContractCall() throws ContractError with sanitized message and raw diagnostic in .details - Tests transaction building, signing, and submission flows for buyPolicy and claim operations - Tests poll-for-confirmation timeout handling - Tests RPC singleton caching for connection pool efficiency (issue Parashield-Protocol#129) - Tests BuyPolicyResult returns signedXdr for backend verification (issue Parashield-Protocol#195)
Uchechukwu-Ekezie
force-pushed
the
fixes/parashield-319-320
branch
from
July 25, 2026 22:09
58c42dc to
7c1d3b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Parashield-Protocol#319 Parashield-Protocol#320
Summary
Implements comprehensive test coverage for two critical library modules:
Issue Parashield-Protocol#319 - api.ts tests:
unwrap()function throwsApiErroron{success:false}response even with HTTP 200 status (critical issue API responses withsuccess: falseon HTTP 200 are treated as successful Parashield-Protocol/parashield-frontend#198)withRetry()behavior: retries on 5xx errors with exponential backoff, throws immediately on 4xx errorsBearertoken to requests when session existsfetchClaim()andfetchOracleReading()Issue Parashield-Protocol#320 - contract.ts tests:
buildBuyPolicyTx()encodes oracle key as{type: 'string'}not{type: 'symbol'}(regression test for issue Oracle key encoded as Sorobansymbol— invalid charset breaksbuy_policyfor most products Parashield-Protocol/parashield-frontend#194)simulateContractCall()throwsContractErrorwith sanitized user-facing message and raw diagnostic in.detailsBuyPolicyResultincludessignedXdrfor backend verification (issue Buy-policy flow never notifies the backend —api.ts'sbuyPolicy()is dead, disconnected code Parashield-Protocol/parashield-frontend#195)Test coverage
src/lib/__tests__/api.test.ts- 292 lines covering api modulesrc/lib/__tests__/contract.test.ts- 260 lines covering contract moduleRelated issues
success: falseon HTTP 200 are treated as successful Parashield-Protocol/parashield-frontend#198 - HTTP 200 with {success:false} should throw errorsymbol— invalid charset breaksbuy_policyfor most products Parashield-Protocol/parashield-frontend#194 - Oracle key encoding regression (symbol → string)api.ts'sbuyPolicy()is dead, disconnected code Parashield-Protocol/parashield-frontend#195 - Pass signed XDR to backendTesting
These tests verify critical error handling paths and transaction encoding that impact production behavior. No breaking changes to existing code.