fix: accept empty attachment_ids, normalize member uuid case, reject repeated query params

This commit is contained in:
2026-11-01 17:51:37 +03:00
parent 210ff67c01
commit 8f8c89cb19
8 changed files with 239 additions and 14 deletions
+54
View File
@@ -209,6 +209,21 @@ describe('API мессенджера (e2e) — граничные случаи
.expect(400);
});
it('считает один UUID в разном регистре дубликатом и узнаёт вызывающего в верхнем регистре', async () => {
const alice = await createUser('alicecase');
await request(server)
.post('/api/v1/chats')
.set('Authorization', bearer(alice))
.send({ title: 'Case', member_ids: [alice.id, alice.id.toUpperCase()] })
.expect(400);
const res = await request(server)
.post('/api/v1/chats')
.set('Authorization', bearer(alice))
.send({ title: 'Upper', member_ids: [alice.id.toUpperCase()] })
.expect(201);
expect(res.body.member_ids).toEqual([alice.id]);
});
it('принимает ровно 100 участников и отклоняет 101', async () => {
const alice = await createUser('max');
const ids = Array.from({ length: 100 }, () => randomUUID());
@@ -304,6 +319,16 @@ describe('API мессенджера (e2e) — граничные случаи
.expect(400);
});
it('отклоняет повторённые limit и cursor', async () => {
const alice = await createUser('pgrepeat');
for (const query of ['limit=1&limit=2', 'cursor=a&cursor=b']) {
await request(server)
.get(`/api/v1/chats?${query}`)
.set('Authorization', bearer(alice))
.expect(400);
}
});
it('отклоняет cursor, не являющийся корректным base64url JSON', async () => {
const alice = await createUser('pgalice4');
await request(server)
@@ -380,6 +405,35 @@ describe('API мессенджера (e2e) — граничные случаи
expect(res.body.error.code).toBe('invalid_request');
});
it('считает attachment_ids: [] равным отсутствию поля, непустой список отклоняет', async () => {
const alice = await createUser('aliceatt');
const bob = await createUser('bobatt');
const chat = await createChat(alice, bob);
const path = `/api/v1/chats/${chat.id}/messages`;
const key = randomUUID();
const first = await request(server)
.post(path)
.set('Idempotency-Key', key)
.set('Authorization', bearer(alice))
.send({ text: 'att' })
.expect(201);
const replay = await request(server)
.post(path)
.set('Idempotency-Key', key)
.set('Authorization', bearer(alice))
.send({ attachment_ids: [], text: 'att' })
.expect(201);
expect(replay.body).toEqual(first.body);
for (const attachment_ids of [[randomUUID()], null, 'x']) {
await request(server)
.post(path)
.set('Idempotency-Key', randomUUID())
.set('Authorization', bearer(alice))
.send({ text: 'x', attachment_ids })
.expect(400);
}
});
it('отклоняет пустое сообщение', async () => {
const alice = await createUser('alice6');
const bob = await createUser('bob6');