Implemented KYB, compliance decisions, integration, and testing
This commit is contained in:
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { createDatabase } from '@merchantflow/database';
|
||||
import { roles, statuses, documentCodes } from '@merchantflow/contracts';
|
||||
import { roles, statuses, documentCodes, requiredDocumentCodes } from '@merchantflow/contracts';
|
||||
import {
|
||||
Role,
|
||||
MerchantStatus,
|
||||
@@ -133,7 +133,7 @@ for (const [account, total] of [
|
||||
for (const m of expected) {
|
||||
const detail = (await request(`/merchants/${m.id}`, cookie)).body;
|
||||
assert.equal(detail.id, m.id);
|
||||
assert.equal(detail.checklist.length, 4);
|
||||
assert.equal(detail.checklist.length, 3);
|
||||
assert.ok(detail.events.every((e) => e.merchant.id === m.id));
|
||||
assert.ok(detail.tasks.every((t) => t.merchant.id === m.id));
|
||||
assert.ok(!JSON.stringify(detail).includes('passwordHash'));
|
||||
@@ -197,10 +197,10 @@ test('filters are validated and review queue is oldest first', async () => {
|
||||
assert.ok(done.every((t) => t.status === 'DONE'));
|
||||
const overdue = (await request('/tasks?filter=OVERDUE', cookie)).body;
|
||||
assert.ok(overdue.every((t) => t.status === 'OPEN' && new Date(t.dueAt) < new Date()));
|
||||
const queue = (await request('/review-queue', cookies.compliance)).body;
|
||||
const queue = (await request('/review-queue', cookies.compliance)).body.items;
|
||||
assert.equal(queue.length, 6);
|
||||
assert.ok(queue.every((m) => m.status === 'COMPLIANCE_REVIEW'));
|
||||
assert.ok(new Date(queue[0].stageEnteredAt) <= new Date(queue[1].stageEnteredAt));
|
||||
assert.ok(queue.every((m) => m.merchant.status === 'COMPLIANCE_REVIEW'));
|
||||
assert.ok(new Date(queue[0].submittedAt) <= new Date(queue[1].submittedAt));
|
||||
});
|
||||
test('seed is repeatable without modifying records; history includes correction and terminal outcomes', async () => {
|
||||
const snapshot = await db.merchant.findMany({
|
||||
@@ -271,7 +271,7 @@ async function fixture(id, status = 'NEW_LEAD', ownerId = 'user-manager1') {
|
||||
contactEmail: '[email protected]',
|
||||
ownerId,
|
||||
status,
|
||||
checklist: { create: documentCodes.map((documentCode) => ({ documentCode })) },
|
||||
checklist: { create: requiredDocumentCodes.map((documentCode) => ({ documentCode })) },
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -313,7 +313,16 @@ test('manager lookup and both directions of direct record/child/mutation attacks
|
||||
{ version: hidden.version, state: 'RECEIVED', note: null },
|
||||
'PATCH',
|
||||
],
|
||||
['/reviews/unknown/decision', { version: hidden.version, decision: 'APPROVED' }, 'POST'],
|
||||
[
|
||||
'/reviews/unknown/decision',
|
||||
{
|
||||
version: hidden.version,
|
||||
decision: 'APPROVED',
|
||||
riskLevel: 'LOW',
|
||||
reason: 'Evidence verified',
|
||||
},
|
||||
'POST',
|
||||
],
|
||||
['/activities', { version: hidden.version, kind: 'NOTE', text: 'Forbidden' }, 'POST'],
|
||||
[
|
||||
`/activities/${hidden.activities[0].id}`,
|
||||
@@ -507,7 +516,12 @@ test('corrections, resubmission, approval and activation preserve one merchant a
|
||||
await mutate(
|
||||
`/merchants/${id}/reviews/${first.id}/decision`,
|
||||
cookie,
|
||||
{ version: m.version, decision: 'APPROVED' },
|
||||
{
|
||||
version: m.version,
|
||||
decision: 'APPROVED',
|
||||
riskLevel: 'LOW',
|
||||
reason: 'Evidence verified',
|
||||
},
|
||||
'POST',
|
||||
)
|
||||
).status,
|
||||
@@ -562,7 +576,12 @@ test('corrections, resubmission, approval and activation preserve one merchant a
|
||||
await mutate(
|
||||
`/merchants/${id}/reviews/${m.reviews[0].id}/decision`,
|
||||
comp,
|
||||
{ version: m.version, decision: 'APPROVED', reason: 'All checks passed' },
|
||||
{
|
||||
version: m.version,
|
||||
decision: 'APPROVED',
|
||||
riskLevel: 'LOW',
|
||||
reason: 'All checks passed',
|
||||
},
|
||||
'POST',
|
||||
)
|
||||
).status,
|
||||
@@ -591,7 +610,37 @@ test('corrections, resubmission, approval and activation preserve one merchant a
|
||||
200,
|
||||
);
|
||||
assert.equal((await move('TESTING', comp)).status, 403);
|
||||
assert.equal((await move('TESTING')).status, 409);
|
||||
for (const code of ['API_CONNECTION', 'WEBHOOK_SETUP']) {
|
||||
const current = await detail();
|
||||
assert.equal(
|
||||
(
|
||||
await mutate(`/merchants/${id}/activation-checks/${code}`, sales, {
|
||||
version: current.version,
|
||||
reviewId: current.reviews[0].id,
|
||||
state: 'COMPLETE',
|
||||
note: 'Demo only',
|
||||
})
|
||||
).status,
|
||||
200,
|
||||
);
|
||||
}
|
||||
assert.equal((await move('TESTING')).status, 201);
|
||||
assert.equal((await move('LIVE', head)).status, 409);
|
||||
for (const code of ['TEST_PAYMENT', 'RECONCILIATION']) {
|
||||
const current = await detail();
|
||||
assert.equal(
|
||||
(
|
||||
await mutate(`/merchants/${id}/activation-checks/${code}`, sales, {
|
||||
version: current.version,
|
||||
reviewId: current.reviews[0].id,
|
||||
state: 'PASSED',
|
||||
note: 'Demo only',
|
||||
})
|
||||
).status,
|
||||
200,
|
||||
);
|
||||
}
|
||||
assert.equal((await move('LIVE', head)).status, 201);
|
||||
assert.equal((await move('REJECTED')).status, 409);
|
||||
m = await detail();
|
||||
@@ -603,7 +652,12 @@ test('corrections, resubmission, approval and activation preserve one merchant a
|
||||
await mutate(
|
||||
`/merchants/${id}/reviews/${first.id}/decision`,
|
||||
comp,
|
||||
{ version: m.version, decision: 'APPROVED' },
|
||||
{
|
||||
version: m.version,
|
||||
decision: 'APPROVED',
|
||||
riskLevel: 'LOW',
|
||||
reason: 'Evidence verified',
|
||||
},
|
||||
'POST',
|
||||
)
|
||||
).status,
|
||||
|
||||
Reference in New Issue
Block a user