You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0bb22c9
Browse filesBrowse the repository at this point in the historyBrowse files
***Execution Environment:**`tsx`, Node `pg` connection pool, `dotenv`
16
17
@@ -76,6 +77,17 @@ The system implements a security and consistency architecture for high-concurren
76
77
5.**Global Centralized Error Interceptor (`errorHandler.middleware.ts`):** Implements Express error handling middleware protecting against internal system information leakage. In production mode (`NODE_ENV=production`), hides database stack traces and returns clean, standardized JSON errors (`500 Internal Server Error`).
77
78
6.**OS Signal Lifecycle & Process Exception Guards (`server.ts`):** Intercepts OS signals (`SIGINT`, `SIGTERM`) to gracefully shut down HTTP connections, clear active interval timers, and disconnect the Prisma database pool. Registers system-wide listeners for `unhandledRejection` and `uncaughtException` events to maintain process stability.
1.**Testing Architecture & Separation of Concerns:** Structured the test environment into dedicated, isolated directories under `tests/` following standard testing pyramid principles:
82
+
***`tests/unit/` (Fast Isolated Logic):** Tests Zod transfer payload validation (`payload.test.ts`) and boot-time environment schema rules (`env.test.ts`) using isolated Jest mocks without hitting external infrastructure.
83
+
***`tests/integration/` (Database & ACID Enforcement):** Validates atomic database transfers, row locks, idempotency duplicate key prevention (`walletTransfer.test.ts`), and negative balance overdraft restrictions (`financialRecovery.test.ts`) against a live PostgreSQL test database instance.
2.**Database Test Seeding & Parity Synchronization (`testDb.ts`):** Engineered custom DB cleanup (`cleanDatabase()`) and seed helpers that initialize a `System Reserve Float` account alongside explicit `CREDIT` ledger transactions to maintain 100% ledger-to-wallet mathematical parity during test runs.
86
+
3.**Environment Log & Noise Optimization:**
87
+
* Configured `src/app.ts` to conditionally suppress HTTP request logging (`morgan`) during test executions (`process.env.NODE_ENV !== "test"`).
88
+
* Integrated console spy handlers (`jest.spyOn(console, "error")`) in deliberate failure unit tests (e.g., short `JWT_SECRET` checks) to maintain clean, clutter-free terminal outputs.
89
+
4.**Verification & Test Suite Results:** Achieved 100% passing status across all **5 test suites (9 individual tests)** executed via Jest with `--runInBand` and open handle detection flags.
90
+
79
91
---
80
92
81
93
## 🗄️ Database Schema Design
@@ -85,6 +97,7 @@ The system implements a security and consistency architecture for high-concurren
85
97
***`WalletTransaction`**: Immutable ledger recording `CREDIT`, `DEBIT`, `REVERSAL_CREDIT`, and `REVERSAL_DEBIT` events. Contains `idempotencyKey`, `senderName`, `receiverName`, and composite B-Tree indexing on `[walletId, createdAt]`.
86
98
***`Product`**: Inventory table incorporating `JSONB` for `metadata`, configured with a PostgreSQL `GIN` index (`JsonbPathOps`) on `metadata` for ultrafast schema-less search and a B-Tree index on `price` for numerical range filtering.
87
99
***`Order` & `OrderItem`**: Normalized checkout records representing snapshot pricing and purchasing relational integrity.
100
+
***`AuditLog`**: Stores discrepancy logs flagged by the background financial reconciliation engine.
88
101
89
102
---
90
103
@@ -119,11 +132,14 @@ npx prisma db seed
119
132
npm run dev
120
133
```
121
134
122
-
### 3. Automated CLI Test Suite
135
+
### 3. Automated CLI & Automated Jest Test Suite Execution
123
136
124
-
Execute CLI test suites to verify atomic transfers, financial reversals, debt recovery, payload validation, status guards, GIN JSONB performance, and B-Tree index optimization:
137
+
Execute Jest or CLI test suites to verify atomic transfers, financial reversals, debt recovery, payload validation, status guards, GIN JSONB performance, and B-Tree index optimization:
125
138
126
139
```bash
140
+
# Execute Complete Automated Jest Test Suite (Unit, Integration, E2E)
0 commit comments