Skip to content

feat: replace in-memory PrismaService fake with real PrismaClient (#475) - #537

Merged
Omoboi-dev merged 5 commits into
JSE-ORG:devfrom
mayborn005:dev
Aug 6, 2026
Merged

feat: replace in-memory PrismaService fake with real PrismaClient (#475)#537
Omoboi-dev merged 5 commits into
JSE-ORG:devfrom
mayborn005:dev

Conversation

@mayborn005

Copy link
Copy Markdown
Contributor
  • Rewrite PrismaService to extend PrismaClient with @prisma/adapter-pg
  • Remove all 13 Map-based in-memory stores (1532 -> 420 lines)
  • reset() now executes TRUNCATE TABLE ... CASCADE
  • Add Postgres 16 service to CI workflow
  • Fix BuyerDisputeService to explicitly transition escrow to DISPUTED
  • Fix vendor-analytics integration test (remove direct store access)
  • Update 4 test files for real PrismaClient API
    closes PrismaService is an in-memory fake; replace it with a real PrismaClient #475

What

Why

Closes #

How

Checklist

  • Linked issue above, and the scope matches what the issue asked for
  • npm run validate passes locally (typecheck, lint, test)
  • Tests added or updated for the changed behaviour
  • Coverage did not drop
  • No any types introduced
  • Services go through a repository, never Prisma directly
  • No secrets, keys, or real addresses committed
  • Changelog updated for consumer-facing changes, or not needed for internal-only work
  • Conventional commit title, for example fix(escrow): correct auto release eligibility query

Notes for the reviewer

…E-ORG#475)

- Rewrite PrismaService to extend PrismaClient with @prisma/adapter-pg
- Remove all 13 Map-based in-memory stores (1532 -> 420 lines)
- reset() now executes TRUNCATE TABLE ... CASCADE
- Add Postgres 16 service to CI workflow
- Fix BuyerDisputeService to explicitly transition escrow to DISPUTED
- Fix vendor-analytics integration test (remove direct store access)
- Update 4 test files for real PrismaClient API
@mayborn005
mayborn005 requested a review from Omoboi-dev as a code owner July 29, 2026 09:04
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@mayborn005 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! 🚀

Learn more about application limits

zeemscript and others added 3 commits July 31, 2026 23:42
Bring the real-PrismaClient PR up to date with base dev (~40 commits).

Conflict resolutions:
- src/prisma/prisma.service.ts: keep the PR's real PrismaClient (drop the
  in-memory fake).
- test/unit/prisma.service.spec.ts, src/prisma/escrow-event-logging.spec.ts:
  keep the PR's real-DB-oriented tests. Upstream's added assertions targeted
  fake-only behaviour (sync throw on plaintext contact, auto-DISPUTED side
  effects, notifications without a parent escrow, no-arg effectiveDatabaseUrl
  undefined) and do not hold against a real PrismaClient.
- .github/workflows/ci.yml: accept upstream's deletion (its coverage/typecheck
  work was consolidated into test.yml in JSE-ORG#525).

Note: this merge is textually clean but not yet green. The fake->real swap
surfaces ~151 type errors in code the base added against the fake's loose
types (Decimal/JsonValue/enums/required itemRef), and @prisma/adapter-pg + pg
still need to be added to package.json. Those are follow-up commits.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HzXa5DbrJ4CsnYs4Sx4qiK
Reconcile the fake->real PrismaClient swap with ~40 commits of base code
that was written against the in-memory fake's loose types.

- Declare the previously-undeclared driver-adapter deps so `npm ci` installs
  them: @prisma/adapter-pg, pg (deps) and @types/pg (devDep).
- prisma.service.ts: enable query-event logging via constructor `log` option
  and narrow $on('query') to Prisma.QueryEvent; drop dead input types; add
  boundary mappers (toEscrowRecord/toFailedTransactionRecord/
  toVendorAccountDetailsRecord/toVendorTrackingSettingsRecord) that convert
  generated rows (Decimal, JsonValue) to the hand-written *Record contract
  (number, plain objects) the rest of the app and its tests depend on.
- escrow / dlq / vendor repositories: convert rows through the mappers;
  write JSON columns via Prisma.DbNull / InputJsonValue.
- admin-stats: Number() the Decimal _sum.amount aggregate.
- analytics: type $queryRaw result as an array.
- schema: add Notification.providerMessageId / attemptCount / lastResponseCode
  (persisted by NotificationsService; previously only in the fake) + migration.

Production `tsc --noEmit` is clean. Remaining type errors are confined to
test/spec files and the benchmark script (follow-up commit).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HzXa5DbrJ4CsnYs4Sx4qiK
…pecs

Make `npm run typecheck` (tsc --noEmit) fully green after the fake->real
PrismaClient migration. Type-only test changes plus repair of pre-existing
bad-merge corruption inherited from base dev.

- Add required `itemRef` to escrow creates; annotate `state: '...' as const`
  where widening broke EscrowRecord/EscrowSummaryDto assignability
  (escrow/dispute/admin-stats/analytics/cross-vendor/tracking-poll specs).
- Add missing fields to VendorTrackingSettingsRecord mocks; cast the DLQ
  ABANDONED record; pass the new DlqService arg to SorobanPollerService;
  use Prisma.DbNull for null JSON columns.
- prisma.service.spec.ts: drop the invalid `@jest/globals` Test import, remove
  unused e1..e4 bindings, Prisma.DbNull for ledgerFeedback.
- Remove duplicated halves left by earlier bad merges in
  tracing.interceptor.spec, tracing.middleware.spec, and
  notification-retry-queue.service.spec.
- config.module.spec.ts: repair the corrupted abortEarly block, the three
  missing sync-test `});`, the duplicate Keypair import, and restore the
  dropped ALL_KNOWN_KEYS definition.
- benchmark script: array-typed $queryRaw, itemRef on seed escrows.

No assertions or test intent changed. Note: the repo-wide `lint:check` job was
already red on base dev (pre-existing prettier/require/console violations in
untouched files); the files changed here are formatted clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HzXa5DbrJ4CsnYs4Sx4qiK
@mayborn005

Copy link
Copy Markdown
Contributor Author

@Omoboi-dev please review and merge PR

- bind this for Prisma query-event logger (v7 Proxy unbound methods)
- single-statement TRUNCATE with advisory lock to avoid reset deadlocks
- seed vendor profiles in tests/seed for escrow FK constraints
- use DisputeStatus enum in admin stats query
- validate ADMIN_ADDRESS with stellarPublicKey schema
- pass encryption key config to LogisticsService constructor
@mayborn005

Copy link
Copy Markdown
Contributor Author

Hi @Omoboi-dev 👋

Just a heads-up: I've pushed an update to this branch (head c57b7bd) with the real-PrismaClient migration fully adapted — services and tests updated for the Prisma v7 client, reset() now uses a single-statement TRUNCATE ... CASCADE with an advisory lock to avoid deadlocks, vendor profiles seeded for the escrow FK constraints, and the admin-stats dispute query now uses the DisputeStatus enum.

However, the 6 CI workflow runs (Test, Lint, E2E, Integration, Docker Build, DB Migrations) are currently waiting for your approval — GitHub's fork-PR gate keeps them at action_required. Could you approve the runs so we can confirm green, and then review/merge? This resolves #475.

Thanks! 🙏

@Omoboi-dev

Copy link
Copy Markdown
Contributor

Hello @mayborn005 will review your pr and merge accordingly.
Thanks.

@Omoboi-dev
Omoboi-dev merged commit 06f291c into JSE-ORG:dev Aug 6, 2026
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PrismaService is an in-memory fake; replace it with a real PrismaClient

3 participants