Repository navigation
fix: resolve test coverage gaps and compilation errors across four issues - #795
Merged
meshackyaro merged 1 commit intoOct 19, 2026
Conversation
…sues This commit addresses four distinct issues that prevented tests from running or compiling, adding 67+ tests and fixing 10+ TypeScript compilation errors. ## Issue trustflow-protocol#731: Zero test coverage for RpcStatusController and PlatformBalanceService ### Added comprehensive test coverage - Created rpc-status.controller.spec.ts with 8 tests covering: * Response shape validation and endpoint status mapping * Date to ISO string conversion * Error field handling (present/absent) * Empty endpoint arrays * JWT authentication requirements via JwtAuthGuard - Created platform-balance.service.spec.ts with 17 tests covering: * Healthy balance scenario (no alert triggered) * WARNING threshold detection and webhook dispatch * CRITICAL threshold detection and webhook dispatch * Alert cooldown mechanism (suppression and expiry) * Missing STELLAR_PLATFORM_ADDRESS early return * stellarService.getBalance() rejection handling * Invalid values (NaN) handling * Webhook dispatch error handling ### Fixed TypeScript strict mode compilation errors - rpc-failover.service.ts: Added definite assignment assertions (!) to properties initialized in constructor-called methods - stellar.config.ts: Added non-null assertions (!) for config values that receive defaults during validation - horizon.helper.ts: Removed deprecated 'timeout' option from Horizon.Server constructor (not supported in stellar-sdk v12) **Result**: 25 passing tests, coverage increased from 0% to >70% for both files ## Issue trustflow-protocol#759: GigController spec compilation errors due to signature mismatch ### Updated test to match current controller signatures All mutating handlers now require AuthenticatedRequest as the final parameter: - create(dto, req) - 2 params - accept(id, dto, req) - 3 params - cancel(id, req) - 2 params - update(id, dto, req) - 3 params Updated all test call sites to pass mock AuthenticatedRequest objects with user.address matching the creator/responder in the test's DTO. ### Added ownership/authorization test coverage - create: Added ForbiddenException test when creator ≠ authenticated wallet - accept: Added ForbiddenException (responder mismatch), BadRequestException (self-accept), and NotFoundException tests - cancel: Added ForbiddenException (non-creator) and NotFoundException tests - update: Added ForbiddenException (non-creator) and NotFoundException tests ### Fixed missing imports - gig.service.ts: Added imports for amountGreaterThanOrEqual and amountLessThanOrEqual from common/amount module **Result**: 24 passing tests, zero TypeScript errors ## Issue trustflow-protocol#760: Syntax error in escrow-reconciliation.service.spec.ts ### Fixed stray closing brace Line 124 had an extra } causing parse failure for the entire rest of the file: Before (incorrect): expect(webhookService.dispatch).toHaveBeenCalledWith( RECONCILIATION_EVENTS.DRIFT_DETECTED, expect.objectContaining({ driftCount: 1 }), }); // <- extra } After (correct): expect(webhookService.dispatch).toHaveBeenCalledWith( RECONCILIATION_EVENTS.DRIFT_DETECTED, expect.objectContaining({ driftCount: 1 }), ); The extra brace broke parsing from line 124 through EOF (line 420), causing cascade errors (TS1135, TS1128) that prevented the entire suite from running. **Result**: File parses correctly, all 18 tests recognized by Jest ## Issue trustflow-protocol#762: Reputation integration spec calling non-existent method ### Migrated to correct dispute entry point - Imported and instantiated EscrowDisputeController (lives in DisputeModule) - Updated raiseDispute call from escrowController (where it never existed) to escrowDisputeController.raiseDispute(id, dto, req) with proper 3-arg signature - Provided complete RaiseDisputeDto with all required fields: * escrowId, reason (min 10 chars), signerAddress ### Fixed compilation errors uncovered by integration test - dispute-saga.service.ts: * Fixed method name: notifyDisputeEscalated → notifyDisputeEscalation * Fixed notification data structure (removed disputeId, added amountXLM) * Commented out non-existent notification methods with TODO markers: notifyJurorsAssigned, notifyVerdictReached, notifyPayoutExecuted - notification.service.ts: Fixed TypeScript strict mode errors in catch blocks (error.message → error instanceof Error ? error.message : String(error)) - soroban.helper.ts: Added non-null assertion for config.SOROBAN_RPC_URL **Result**: File compiles cleanly, 4 tests recognized (fail on runtime config, not compilation) ## Summary - 67+ tests added/fixed across 4 issues - 10+ TypeScript compilation errors resolved - Zero test coverage → comprehensive coverage for RpcStatus and PlatformBalance - All test suites now compile and can execute their assertions Closes trustflow-protocol#731 Closes trustflow-protocol#759 Closes trustflow-protocol#760 Closes trustflow-protocol#762
|
@Joeloo1 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! 🚀 |
4 tasks
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.
Overview
This PR resolves four distinct issues that prevented test suites from compiling or running, adding 67+ tests and fixing 10+ TypeScript compilation errors across the backend codebase.
Closes #731
Closes #759
Closes #760
Closes #762
Issue #731: Zero test coverage for RpcStatusController and PlatformBalanceService
Problem
rpc-status.controller.ts(GET/rpc-status) had 0% test coverage — no spec file existedplatform-balance.service.ts(@Cron job monitoring platform balance) had 0% test coverage — no spec file existedSolution
Created
rpc-status.controller.spec.ts(8 tests)RpcFailoverServiceendpoint arrays to documented response structurelastCheckedDate objects are properly serialized to ISO stringslastErroris included when present, omitted when undefinedJwtAuthGuarddecoratorCreated
platform-balance.service.spec.ts(17 tests)Comprehensive coverage of the balance monitoring cron job:
STELLAR_PLATFORM_ADDRESSis undefined/emptystellarService.getBalance()rejection is caught and logged, no throwFixed TypeScript strict mode compilation errors
These errors were blocking test execution even though they existed in production code:
rpc-failover.service.ts: Added definite assignment assertions (!) tocurrentHorizonEndpoint,currentSorobanEndpoint, andhealthCheckInterval— properties are initialized ininitializeEndpoints()called from constructor, but TypeScript strict mode requires explicit markingstellar.config.ts: Added non-null assertions (!) forconfig.STELLAR_HORIZON_URLandconfig.SOROBAN_RPC_URL— these receive defaults during env validation but the Zod schema marks them optional, requiring runtime assertionhorizon.helper.ts: Removed deprecatedtimeoutoption fromHorizon.Serverconstructor — not supported in@stellar/stellar-sdkv12Impact
npm run test:ciIssue #759: GigController spec compilation errors due to signature mismatch
Problem
gig.controller.spec.tsfailed to compile with 5 TypeScript errors:The spec was calling controller methods with the old signature (pre-ownership-checks), but
GigControllernow requires anAuthenticatedRequestparameter on all mutating endpoints to verifyreq.user.addressmatches the DTO's creator/responder:create(dto, req)— 2 paramsaccept(id, dto, req)— 3 paramscancel(id, req)— 2 paramsupdate(id, dto, req)— 3 paramsBecause the suite failed to compile, none of its assertions were executing — including valid tests like "rejects an invalid creator address before hitting the service."
Solution
Updated all call sites to pass mock
AuthenticatedRequestEvery test now constructs a mock request object with
user.addressmatching the DTO's creator/responder:Added comprehensive ownership/authorization test coverage (8 new tests)
Since the controller now enforces ownership via
ForbiddenException, added tests to verify:create:
ForbiddenExceptionwhendto.creator ≠ req.user.addressaccept:
ForbiddenExceptionwhendto.responder ≠ req.user.addressBadRequestExceptionwhen trying to accept own gig (depositor === responder)NotFoundExceptionwhen gig doesn't existcancel:
ForbiddenExceptionwhen caller is not the gig creatorNotFoundExceptionwhen gig doesn't existupdate:
ForbiddenExceptionwhen caller is not the gig creatorNotFoundExceptionwhen gig doesn't existFixed missing imports in
gig.service.tsThe service was calling
amountGreaterThanOrEqual()andamountLessThanOrEqual()but hadn't imported them fromcommon/amount, causing additional compilation errors.Impact
Issue #760: Syntax error in escrow-reconciliation.service.spec.ts
Problem
The file had a stray closing brace on line 124 that broke parsing for the entire rest of the file:
This caused a cascade of unrelated-looking parse errors:
Because the file didn't parse, the entire suite (18 tests) failed to run — drift-detection, repair, concurrency-limit, and error-handling assertions were all dead code.
Solution
Removed the extra
}so theexpect(...).toHaveBeenCalledWith(...)call closes with);:Confirmed no other similar brace mismatches exist in the file.
Impact
npx tsc --noEmit -p tsconfig.eslint.jsonreports zero errors for this fileIssue #762: Reputation integration spec calling non-existent method
Problem
reputation.integration.spec.tswas calling a method that doesn't exist:EscrowControllerhas never had araiseDisputemethod in this snapshot. The method lives onEscrowDisputeController(inDisputeModule) because:DisputeModulealready depends onEscrowModuleDisputeSagaService.escalate()is now "the single off-chain entry point"Because the suite failed to compile, none of its reputation-scoring assertions were running — the escrow → reputation flow (raise dispute → resolve → check score change) was untested.
Solution
Migrated to the correct dispute entry point
Imported
EscrowDisputeControllerfromdispute/escrow-dispute.controllerInstantiated the controller in
beforeEachviamodule.get(EscrowDisputeController)Updated the test call to use the real controller with correct 3-arg signature:
EscrowDisputeController.raiseDispute(id, dto, req)requires:id: escrow ID (path param)dto:RaiseDisputeDtowithescrowId,reason(min 10 chars),signerAddressreq:AuthenticatedRequestwithuser.addressmatching depositor/beneficiaryFixed compilation errors uncovered by running the integration test
The integration test imports real modules (not mocks), which surfaced additional compilation issues:
dispute-saga.service.ts:Fixed method name:
notifyDisputeEscalated→notifyDisputeEscalation(typo; actual method ends in-ion)Fixed notification data structure: removed
disputeId(doesn't exist onDisputeNotificationData), addedamountXLM(required field)Commented out non-existent methods with TODO markers:
notifyJurorsAssigned()notifyVerdictReached()notifyPayoutExecuted()These were called but never implemented in
NotificationService— left as TODOs rather than implementing stubbed-out functionalitynotification.service.ts: Fixed TypeScript strict mode errors in catch blocks:soroban.helper.ts: Added non-null assertion forconfig.SOROBAN_RPC_URL(same pattern as stellar.config.ts fix from issue RpcStatusController and PlatformBalanceService have zero test coverage #731)Impact
Summary of Changes
Files Added (2)
backend/src/stellar/rpc-status.controller.spec.ts— 8 testsbackend/src/stellar/platform-balance.service.spec.ts— 17 testsFiles Modified (10)
backend/src/stellar/rpc-failover.service.ts— definite assignment assertionsbackend/src/stellar/stellar.config.ts— non-null assertions for config valuesbackend/src/stellar/horizon.helper.ts— removed deprecated timeout optionbackend/src/stellar/soroban.helper.ts— non-null assertion for RPC URLbackend/src/gig/gig.controller.spec.ts— updated signatures + 8 new auth testsbackend/src/gig/gig.service.ts— added missing amount comparison importsbackend/src/escrow-reconciliation/escrow-reconciliation.service.spec.ts— fixed stray bracebackend/src/reputation/reputation.integration.spec.ts— migrated to EscrowDisputeControllerbackend/src/dispute/dispute-saga.service.ts— fixed notification method names + data structuresbackend/src/notification/notification.service.ts— fixed TypeScript strict mode errorsTest Results
Verification Commands
Testing Notes
All test suites in this PR were verified to:
The reputation integration test suite fails at runtime due to missing
validateEnv()call, but this is a pre-existing setup issue unrelated to the compilation fixes in this PR — the test compiles cleanly and is now executable, which was the goal of issue #762.Related Issues
Closes #731 — Zero test coverage for RpcStatusController and PlatformBalanceService
Closes #759 — GigController spec compilation errors
Closes #760 — Syntax error in escrow-reconciliation spec
Closes #762 — Reputation integration spec calling non-existent method