Implemented KYB, compliance decisions, integration, and testing

This commit is contained in:
Oleksandr Prokhorenko
2026-09-24 21:31:42 +03:00
parent 382f6e8841
commit 1f8721e742
36 changed files with 2279 additions and 233 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ try {
})),
},
checklist: {
create: documentCodes.map((documentCode, j) => ({
create: documentCodes.slice(0, 4).map((documentCode, j) => ({
id: `${id}-doc-${j}`,
documentCode,
state:
+1 -1
View File
@@ -169,7 +169,7 @@ for (const language of ['en', 'ru'])
expect(merchants[0]?.ownerId).toBeNull();
expect(merchants[0]?.activities).toHaveLength(1);
expect(merchants[0]?.events).toHaveLength(1);
expect(merchants[0]?.checklist).toHaveLength(4);
expect(merchants[0]?.checklist).toHaveLength(3);
expect(runtimeErrors).toEqual([]);
});
});
+224
View File
@@ -0,0 +1,224 @@
import { test, expect, type APIRequestContext } from '@playwright/test';
import { createDatabase } from '../packages/database/dist/index.js';
const origin = 'http://127.0.0.1:5174';
async function login(request: APIRequestContext, actor: string) {
const result = await request.post('/api/auth/login', {
headers: { origin },
data: { email: `${actor}@merchantflow.test`, password: 'MerchantFlow123!' },
});
expect(result.status()).toBe(201);
}
async function pending(request: APIRequestContext, name: string) {
await login(request, 'head');
const created = await request.post('/api/merchants', {
headers: { origin },
data: {
name,
contactName: 'Queue Contact',
contactEmail: '[email protected]',
website: 'https://queue.test',
country: 'GB',
industry: 'SOFTWARE',
estimatedMonthlyVolumeUsd: '0',
ownerId: 'user-manager1',
},
});
expect(created.status()).toBe(201);
const { id } = await created.json();
const detail = async () => (await request.get(`/api/merchants/${id}`)).json();
const mutate = async (path: string, data: object, method = 'POST') => {
const response = await request.fetch(`/api/merchants/${id}${path}`, {
method,
headers: { origin },
data: { version: (await detail()).version, ...data },
});
expect(response.ok()).toBe(true);
};
await mutate('/activities', { kind: 'CALL', text: 'Confirmed onboarding requirements' });
for (const toStatus of ['CONTACTED', 'QUALIFIED', 'KYB'])
await mutate('/transitions', { toStatus });
for (const item of (await detail()).checklist)
await mutate(
`/checklist/${item.id}`,
{ state: 'RECEIVED', note: 'Received for review' },
'PATCH',
);
await mutate('/transitions', { toStatus: 'COMPLIANCE_REVIEW' });
return await detail();
}
async function remove(id: string) {
if (!process.env.DATABASE_URL?.endsWith('/merchantflow_test'))
throw new Error('Test database only');
const db = createDatabase(process.env.DATABASE_URL);
try {
await db.merchant.delete({ where: { id } });
} finally {
await db.$disconnect();
}
}
for (const language of ['en', 'ru'])
for (const width of [390, 1440]) {
test(`Compliance queue, review validation and rejection ${language} ${width}px`, async ({
page,
}, info) => {
await page.setViewportSize({ width, height: 1000 });
await page.addInitScript(
(lang) => localStorage.setItem('merchantflow.language', lang),
language,
);
const name = `Queue specimen ${language} ${width}`;
const merchant = await pending(page.request, name);
try {
await login(page.request, 'compliance');
await page.goto('/app/review-queue');
const search = page.getByRole('textbox', { name: /Search merchants|Поиск мерчантов/ });
await search.fill(name);
await page
.getByRole('combobox', { name: /Account manager|Аккаунт-менеджер/ })
.selectOption('user-manager1');
await expect(page.locator('article')).toHaveCount(1);
await expect(page.locator('article')).toContainText(/Waiting|Ожидание/);
await page
.getByRole('combobox', { name: /Waiting time|Время ожидания/ })
.selectOption('24');
await expect(page.locator('article')).toHaveCount(0);
await expect(page).toHaveURL(/waiting=24/);
await page.reload();
await expect(search).toHaveValue(name);
await page
.getByRole('combobox', { name: /Waiting time|Время ожидания/ })
.selectOption('ALL');
await expect(page.locator('article')).toHaveCount(1);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(
true,
);
await page.screenshot({ path: info.outputPath('review-queue.png'), fullPage: true });
const pendingId = merchant.reviews[0].id;
await page.getByRole('link', { name: /Open review|Открыть проверку/ }).click();
await expect(page).toHaveURL(new RegExp(`tab=onboarding#review-${pendingId}`));
await expect(page.locator(`#review-${pendingId}`)).toBeFocused();
await expect(
page.getByRole('button', { name: /Update collection|Обновить сбор/ }),
).toHaveCount(0);
await page
.getByRole('button', { name: /Record decision|Записать решение/, exact: true })
.click();
const dialog = page.getByRole('dialog');
await dialog.getByRole('button', { name: /^(Approve|Одобрить)$/ }).click();
await expect(dialog.getByLabel(/Risk level|Уровень риска/)).toHaveAttribute(
'aria-invalid',
'true',
);
await dialog.getByLabel(/Decision$|^Решение$/).selectOption('REJECTED');
await expect(dialog.getByLabel(/Risk level|Уровень риска/)).toHaveCount(0);
await dialog.getByRole('button', { name: /^(Reject|Отклонить)$/ }).click();
const reason = dialog.getByLabel(/Rejection reason|Причина отклонения/);
await expect(reason).toHaveAttribute('aria-invalid', 'true');
await reason.fill('Representative authority could not be confirmed.');
await page.route(
'**/api/merchants/*/reviews/*/decision',
(route) =>
route.fulfill({
status: 409,
contentType: 'application/json',
body: JSON.stringify({ code: 'CONFLICT' }),
}),
{ times: 1 },
);
await dialog.getByRole('button', { name: /^(Reject|Отклонить)$/ }).click();
await expect(dialog.getByRole('alert')).toBeVisible();
await expect(reason).toHaveValue('Representative authority could not be confirmed.');
await dialog.getByRole('button', { name: /^(Reject|Отклонить)$/ }).click();
await expect(dialog).not.toBeVisible();
await expect
.poll(
async () =>
(await (await page.request.get(`/api/merchants/${merchant.id}`)).json()).status,
)
.toBe('REJECTED');
await page.reload();
await expect(page.locator(`#review-${pendingId}`)).toContainText(
'Representative authority could not be confirmed.',
);
await expect(
page.getByRole('button', { name: /Record decision|Записать решение/ }),
).toHaveCount(0);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(
true,
);
await page.screenshot({ path: info.outputPath('rejected-review.png'), fullPage: true });
} finally {
await remove(merchant.id);
}
});
}
test('an open decision form stays bound to its original cycle after another reviewer requests changes and Sales resubmits', async ({
page,
browser,
}) => {
const merchant = await pending(page.request, 'Stale decision form specimen');
const staff = await browser.newContext({ baseURL: origin });
try {
await login(staff.request, 'head');
await login(page.request, 'compliance');
await page.goto(`/app/merchants/${merchant.id}?tab=onboarding`);
await page.getByRole('button', { name: 'Record decision', exact: true }).click();
const dialog = page.getByRole('dialog');
await dialog.getByLabel('Risk level', { exact: true }).selectOption('LOW');
await dialog
.getByLabel('Approval rationale (required)', { exact: true })
.fill('Assessment of the original submission.');
const reviewId = merchant.reviews[0].id;
const itemId = merchant.checklist[0].id;
const correction = await page.request.post(
`/api/merchants/${merchant.id}/reviews/${reviewId}/decision`,
{
headers: { origin },
data: {
version: merchant.version,
decision: 'CORRECTIONS',
reason: 'A newer record is required',
corrections: [{ itemId, note: 'Collect the updated record' }],
},
},
);
expect(correction.status()).toBe(201);
const detail = async () => (await staff.request.get(`/api/merchants/${merchant.id}`)).json();
const collect = await staff.request.patch(`/api/merchants/${merchant.id}/checklist/${itemId}`, {
headers: { origin },
data: {
version: (await detail()).version,
state: 'RECEIVED',
note: 'New submission evidence',
},
});
expect(collect.status()).toBe(200);
const submit = await staff.request.post(`/api/merchants/${merchant.id}/transitions`, {
headers: { origin },
data: { version: (await detail()).version, toStatus: 'COMPLIANCE_REVIEW' },
});
expect(submit.status()).toBe(201);
const newReviewId = (await detail()).reviews[0].id;
expect(newReviewId).not.toBe(reviewId);
for (let attempt = 0; attempt < 2; attempt++) {
const response = page.waitForResponse((response) =>
response.url().includes(`/reviews/${reviewId}/decision`),
);
await dialog.getByRole('button', { name: 'Approve', exact: true }).click();
expect((await response).status()).toBe(409);
await expect(dialog.getByRole('alert')).toBeVisible();
await expect(dialog.getByLabel('Approval rationale (required)', { exact: true })).toHaveValue(
'Assessment of the original submission.',
);
}
const current = await detail();
expect(current.status).toBe('COMPLIANCE_REVIEW');
expect(current.reviews[0].decision).toBe('PENDING');
expect(current.reviews[0].id).toBe(newReviewId);
} finally {
await staff.close();
await remove(merchant.id);
}
});
+34 -11
View File
@@ -130,7 +130,7 @@ test('account switching removes old data, manager isolation and Compliance navig
expect((await (await page.request.get('/api/dashboard')).json()).merchantCount).toBe(45);
await page.getByRole('link', { name: 'Review queue', exact: true }).click();
await expect(page.getByRole('heading', { name: '6 merchants awaiting review' })).toBeVisible();
await page.getByRole('link', { name: 'View checklist' }).first().click();
await page.getByRole('link', { name: 'Open review' }).first().click();
await expect(page.getByRole('heading', { name: 'KYB checklist' })).toBeVisible();
await page.goto('/app/merchants/merchant-15');
await expect(page.locator('h1')).toHaveText('Sunday Market');
@@ -264,11 +264,11 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
await advance('Qualified');
await advance('KYB');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
for (let i = 0; i < 4; i++) {
await page.getByRole('button', { name: 'Update document', exact: true }).nth(i).click();
for (let i = 0; i < 3; i++) {
await page.getByRole('button', { name: 'Update collection', exact: true }).nth(i).click();
await page
.getByRole('dialog')
.getByLabel('Document status', { exact: true })
.getByLabel('Collection status', { exact: true })
.selectOption('RECEIVED');
await save();
}
@@ -283,26 +283,30 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
.selectOption('CORRECTIONS');
await page
.getByRole('dialog')
.getByLabel('Decision reason', { exact: true })
.getByLabel('Required changes (required)', { exact: true })
.fill('The ownership declaration needs a current signature.');
await page
.getByRole('dialog')
.getByLabel('Ownership structure', { exact: true })
.fill('Please sign and date the declaration.');
await save();
await page
.getByRole('dialog')
.getByRole('button', { name: 'Request changes', exact: true })
.click();
await expect(page.getByRole('dialog')).not.toBeVisible();
await switchAccount('alex');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
const ownership = page
.locator('#checklist > div > div')
.filter({ hasText: 'Ownership structure' });
await ownership.getByRole('button', { name: 'Update document', exact: true }).click();
await ownership.getByRole('button', { name: 'Update collection', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Document status', { exact: true })
.getByLabel('Collection status', { exact: true })
.selectOption('RECEIVED');
await page
.getByRole('dialog')
.getByLabel('Note', { exact: true })
.getByLabel('Collection notes', { exact: true })
.fill('Updated signature received.');
await save();
await advance('Compliance Review');
@@ -311,9 +315,11 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
await page.getByRole('button', { name: 'Record decision', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Decision reason', { exact: true })
.getByLabel('Approval rationale (required)', { exact: true })
.fill('All evidence checked and approved.');
await save();
await page.getByRole('dialog').getByLabel('Risk level', { exact: true }).selectOption('LOW');
await page.getByRole('dialog').getByRole('button', { name: 'Approve', exact: true }).click();
await expect(page.getByRole('dialog')).not.toBeVisible();
await expect(page.getByRole('button', { name: 'Edit merchant', exact: true })).toHaveCount(0);
await switchAccount('alex');
await page.getByRole('button', { name: 'Edit merchant', exact: true }).click();
@@ -321,7 +327,24 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
page.getByRole('dialog').getByLabel('Legal company name', { exact: true }),
).toBeDisabled();
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
const check = async (name: string, result: string) => {
const row = page
.locator('article')
.filter({ has: page.getByRole('heading', { name, exact: true }) });
await row.getByRole('button', { name: 'Update demo check' }).click();
await page.getByRole('dialog').getByLabel('Result', { exact: true }).selectOption(result);
await save();
};
await expect(page.getByRole('button', { name: 'Move to Testing', exact: true })).toBeDisabled();
await check('API connection', 'COMPLETE');
await check('Webhook setup', 'COMPLETE');
await advance('Testing');
await expect(page.getByRole('button', { name: 'Move to Live', exact: true })).toBeDisabled();
await check('Test payment', 'FAILED');
await check('Reconciliation', 'PASSED');
await expect(page.getByRole('button', { name: 'Move to Live', exact: true })).toBeDisabled();
await check('Test payment', 'PASSED');
await advance('Live');
await noOverflow(page);
await page.screenshot({ path: info.outputPath('approved-live-merchant.png'), fullPage: true });