Skip to content

test: add unit tests for TransactionStatusCheckerProcessor and LoanPaymentReminderProcessor #121

Description

@Josue19-08

🔖 Title

Add unit tests for `TransactionStatusCheckerProcessor` and `LoanPaymentReminderProcessor`


📄 Description

`test/unit/jobs/` contains only `blockchain-indexer.processor.spec.ts`. Two other job processors with significant business logic are completely untested:

`TransactionStatusCheckerProcessor` — critical paths with no test coverage:

  • Horizon retry with exponential back-off (transient errors silently swallowed if retries exhausted)
  • `parseTransactionMetadata()` — parses raw Stellar XDR to extract `loanId` and `amount` from `invokeHostFunction` operations; a parsing bug here silently misapplies payments to wrong loans
  • `activatePendingLoan()` and `applyLoanRepayment()` — DB mutations triggered by XDR parse result
  • Notification creation on loan activation and repayment
  • `cleanupOldTransactions()` scheduled deletion

`LoanPaymentReminderProcessor` — date-boundary logic with no test coverage:

  • 3-day reminder window calculation
  • 1-day reminder window calculation
  • Overdue detection
  • Duplicate notification skip (same loan, same window, reminder already sent)

✅ Tasks to complete

  • Create `test/unit/jobs/transaction-status-checker/transaction-status-checker.processor.spec.ts`:
    • Successful `create_loan` XDR → loan activated, notification created
    • Successful `repay_loan` XDR → repayment applied, reputation update triggered
    • Horizon transient error → retries up to max; logs warning; does not throw
    • Horizon 404 (not found) → transaction marked as failed gracefully
    • XDR parse failure → processor logs error, does not crash, marks transaction failed
    • `cleanupOldTransactions()` → calls repository delete with correct cutoff date
  • Create `test/unit/jobs/loan-payment-reminder/loan-payment-reminder.processor.spec.ts`:
    • Loan due in 3 days → 3-day reminder notification created
    • Loan due in 1 day → 1-day reminder notification created
    • Loan overdue → overdue notification created
    • Loan with reminder already sent for that window → no duplicate notification
    • Loan already completed → skipped
  • Create `test/fixtures/jobs.fixtures.ts` — add typed fixtures: pending transactions, sample XDR for `invokeHostFunction`, active loans with due dates at various offsets
  • Create or extend `test/helpers/` — add BullMQ `Job` mock factory and Supabase query chain mock
  • Refactor `src/jobs/transaction-status-checker/transaction-status-checker.processor.ts` — export `parseTransactionMetadata` as `protected` (or extract to a pure utility function) to enable isolated unit testing without running the full processor
  • Refactor `src/jobs/loan-payment-reminder/loan-payment-reminder.processor.ts` — extract date-window calculation into a pure function `getReminderWindow(dueDate: Date, now: Date): 'three-day' | 'one-day' | 'overdue' | null` for isolated testing

📚 Documentation/context for AI

(This link never should removed)
https://github.com/TrustUp-app/TrustUp-API/tree/main/docs

Relevant files:

  • `src/jobs/transaction-status-checker/transaction-status-checker.processor.ts`
  • `src/jobs/loan-payment-reminder/loan-payment-reminder.processor.ts`
  • `test/unit/jobs/blockchain-indexer.processor.spec.ts` — use as pattern reference
  • `test/fixtures/`
  • `test/helpers/`

🗒️ Additional notes

  • Use `jest.useFakeTimers()` for date-sensitive tests in the reminder processor to control `new Date()` without flakiness
  • XDR fixtures can be generated via `StellarSdk.xdr` in a test setup script — commit the base64 string directly to `test/fixtures/` to avoid SDK calls in tests
  • BullMQ `Job` mock only needs `id`, `name`, and `data` fields for these processors
  • The `parseTransactionMetadata` extraction should not change public API — it is an internal refactor for testability only

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions