Added some small enchances

This commit is contained in:
Oleksandr Prokhorenko
2026-09-24 22:41:06 +03:00
parent 9ccbac4aca
commit 7f3a56a4ca
21 changed files with 441 additions and 211 deletions
+26 -7
View File
@@ -142,7 +142,7 @@ test('staff creation is atomic, minimally required, role-bound and strict', asyn
test('search, combined filters, pagination and metadata apply ownership scope before counts', async () => {
const prefix = `Directory-${randomUUID()}`;
const ids = [];
for (let index = 0; index < 10; index++)
for (let index = 0; index < 31; index++)
ids.push(
await create('alex', {
name: `${prefix} ${index}`,
@@ -174,11 +174,20 @@ test('search, combined filters, pagination and metadata apply ownership scope be
const query = `search=${prefix}&country=GB&industry=SOFTWARE&status=NEW_LEAD`;
const page1 = (await request(`/merchants?${query}`, 'alex')).body;
const page2 = (await request(`/merchants?${query}&page=2`, 'alex')).body;
assert.equal(page1.total, 10);
assert.equal(page1.items.length, 8);
assert.equal(page2.items.length, 2);
assert.equal(new Set([...page1.items, ...page2.items].map((m) => m.id)).size, 10);
assert.equal((await request(`/merchants?${query}&page=10000`, 'alex')).body.page, 2);
assert.equal(page1.total, 31);
assert.equal(page1.items.length, 10);
assert.equal(page2.items.length, 10);
assert.equal(new Set([...page1.items, ...page2.items].map((m) => m.id)).size, 20);
assert.equal((await request(`/merchants?${query}&page=10000`, 'alex')).body.page, 4);
for (const pageSize of [10, 20, 30]) {
const first = (await request(`/merchants?${query}&pageSize=${pageSize}`, 'alex')).body;
const last = (await request(`/merchants?${query}&pageSize=${pageSize}&page=10000`, 'alex'))
.body;
assert.equal(first.pageSize, pageSize);
assert.equal(first.items.length, pageSize);
assert.equal(last.page, Math.ceil(31 / pageSize));
assert.equal(last.items.length, 31 % pageSize);
}
assert.equal((await request(`/merchants?${query}&ownerId=user-manager2`, 'alex')).status, 403);
assert.equal(
(await request(`/merchants?search=${prefix}&ownerId=user-manager2`, 'head')).body.items[0].id,
@@ -190,7 +199,17 @@ test('search, combined filters, pagination and metadata apply ownership scope be
unassigned,
);
assert.equal((await request(`/merchants?search=${prefix}&country=JP`, 'alex')).body.total, 0);
for (const invalid of ['country=ZZ', 'industry=INVALID', 'status=Live', 'page=1.5', 'page=-1'])
for (const invalid of [
'country=ZZ',
'industry=INVALID',
'status=Live',
'page=1.5',
'page=-1',
'pageSize=8',
'pageSize=0',
'pageSize=15',
'pageSize=1000',
])
assert.equal((await request(`/merchants?${invalid}`)).status, 400);
const ownFilters = merchantFiltersSchema.parse(
(await request('/merchants/filters', 'alex')).body,