Implemented KYB, compliance decisions, integration, and testing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user