Skip to content

test(backend): mock db/connection in defaultChecker.test.ts to unblock CI - #2037

Open
aazminu wants to merge 1 commit into
LabsCrypt:mainfrom
aazminu:fix-ci-default-checker-test-db-mock
Open

aazminu wants to merge 1 commit into
LabsCrypt:mainfrom
aazminu:fix-ci-default-checker-test-db-mock

Conversation

@aazminu

@aazminu aazminu commented Oct 19, 2026

Copy link
Copy Markdown

Summary

Unblocks the backend GitHub Actions CI job by mocking ../db/connection.js in backend/src/__tests__/defaultChecker.test.ts.

Root Cause

DefaultChecker.checkOverdueLoans() calls the module-level backfillExtensionDueLedgers() helper (backend/src/services/defaultChecker.ts:602), which executes query(...) from ../db/connection.js before invoking this.fetchOverdueStats(...). While backend/src/services/__tests__/defaultChecker.test.ts mocked db/connection.js via jest.unstable_mockModule, backend/src/__tests__/defaultChecker.test.ts imported DefaultChecker directly without mocking ../db/connection.js, causing npm test in CI (which runs without a live PostgreSQL service on 127.0.0.1:5432) to fail with connect ECONNREFUSED 127.0.0.1:5432 at backfillExtensionDueLedgers.

Changes

  • backend/src/__tests__/defaultChecker.test.ts:
    • Mock ../db/connection.js via jest.unstable_mockModule prior to importing ../services/defaultChecker.js, matching backend/src/services/__tests__/defaultChecker.test.ts.
    • Configure mockQuery in beforeEach to resolve { rows: [], rowCount: 0 } and assert that backfillExtensionDueLedgers's LoanExtended query is invoked.

Verification

  • node --experimental-vm-modules node_modules/jest/bin/jest.js src/__tests__/defaultChecker.test.ts src/services/__tests__/defaultChecker.test.ts --forceExit (2/2 suites, 19/19 tests pass)
  • npx eslint src/__tests__/defaultChecker.test.ts (0 errors)
  • npm run typecheck (0 errors)

Payout / Reward Wallet

  • EVM (USDT / USDC): 0x9a51790aC01c54184bcFa067bC38f7F0E7C6F6B6

@aazminu
aazminu force-pushed the fix-ci-default-checker-test-db-mock branch from 3f4b1f8 to add2c72 Compare October 24, 2026 06:11
@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Oct 24, 2026
@github-actions

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 1 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • backend/src/__tests__/defaultChecker.test.ts — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

@aazminu
aazminu force-pushed the fix-ci-default-checker-test-db-mock branch 2 times, most recently from 4dea6b6 to fe303ee Compare October 24, 2026 06:58
@aazminu
aazminu force-pushed the fix-ci-default-checker-test-db-mock branch from fe303ee to 9e1d701 Compare October 24, 2026 06:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant