openvibers/openvibe.community Commits
Poll the relay inbound API for the recorded failure before asserting it (#13)
Changes
@@@ -319,10 +319,15 @@ const sent = (gw, op) => gw.sockets.flatMap((s) => s.sent).filter((p) => p.op ==assert.ok(page.text.includes('badge-relay') && page.text.includes('Kim') && page.text.includes('<strong>great</strong>'), 'the reply shows with its Discord badge');await t.db.prepare('UPDATE threads SET locked = 1').run();gw.dispatch('MESSAGE_CREATE', { id: locked, channel_id: anchor.external_channel_id, type: 19, content: 'too late', author: { id: KIM, username: 'kim' }, message_reference: { message_id: anchor.external_message_id } });-- // Handling is async (the gateway queues dispatches): wait for the failure to be recorded before reading it.-- await waitFor(async () => await t.db.prepare("SELECT 1 FROM relay_inbound_failures WHERE error = 'the thread is locked'").get(), 'the locked reply recorded as a failure');assert.strictEqual((await call('/api/v1/relay/inbound', { cookie: samJwt })).status, 403);-- const inb =await call('/api/v1/relay/inbound', { cookie: adminJwt });++ // Handling is async (the gateway queues dispatches), so poll the API for the failure itself — the exact++ // condition asserted below — instead of reading once and hoping the record is already there.++ let inb;++ await waitFor(async () => {++ inb = await call('/api/v1/relay/inbound', { cookie: adminJwt });++ const f = inb.json().failures;++ return f.length === 1 && f[0].error === 'the thread is locked' && f[0].discord.message_id === locked && f[0].mapping.space === 'general';++ }, 'the locked reply listed at /api/v1/relay/inbound');assert.strictEqual(inb.status, 200);assert.deepStrictEqual(inb.json().failures.map((f) => [f.error, f.discord.message_id, f.mapping.space]), [['the thread is locked', locked, 'general']]);assert.strictEqual((await call(`/api/v1/relay/inbound/${inb.json().failures[0].id}/dismiss`, { method: 'POST', cookie: adminJwt })).status, 200);
@@ -319,10 +319,15 @@ const sent = (gw, op) => gw.sockets.flatMap((s) => s.sent).filter((p) => p.op ==
@@ -319,10 +319,15 @@ const sent = (gw, op) => gw.sockets.flatMap((s) => s.sent).filter((p) => p.op ==
assert.ok(page.text.includes('badge-relay') && page.text.includes('Kim') && page.text.includes('<strong>great</strong>'), 'the reply shows with its Discord badge');
assert.ok(page.text.includes('badge-relay') && page.text.includes('Kim') && page.text.includes('<strong>great</strong>'), 'the reply shows with its Discord badge');
await t.db.prepare('UPDATE threads SET locked = 1').run();
await t.db.prepare('UPDATE threads SET locked = 1').run();
gw.dispatch('MESSAGE_CREATE', { id: locked, channel_id: anchor.external_channel_id, type: 19, content: 'too late', author: { id: KIM, username: 'kim' }, message_reference: { message_id: anchor.external_message_id } });
gw.dispatch('MESSAGE_CREATE', { id: locked, channel_id: anchor.external_channel_id, type: 19, content: 'too late', author: { id: KIM, username: 'kim' }, message_reference: { message_id: anchor.external_message_id } });
- // Handling is async (the gateway queues dispatches): wait for the failure to be recorded before reading it.
- await waitFor(async () => await t.db.prepare("SELECT 1 FROM relay_inbound_failures WHERE error = 'the thread is locked'").get(), 'the locked reply recorded as a failure');
assert.strictEqual((await call('/api/v1/relay/inbound', { cookie: samJwt })).status, 403);
assert.strictEqual((await call('/api/v1/relay/inbound', { cookie: samJwt })).status, 403);
- const inb =await call('/api/v1/relay/inbound', { cookie: adminJwt });
+ // Handling is async (the gateway queues dispatches), so poll the API for the failure itself — the exact
+ // condition asserted below — instead of reading once and hoping the record is already there.
+ let inb;
+ await waitFor(async () => {
+ inb = await call('/api/v1/relay/inbound', { cookie: adminJwt });
+ const f = inb.json().failures;
+ return f.length === 1 && f[0].error === 'the thread is locked' && f[0].discord.message_id === locked && f[0].mapping.space === 'general';
+ }, 'the locked reply listed at /api/v1/relay/inbound');
assert.strictEqual(inb.status, 200);
assert.strictEqual(inb.status, 200);
assert.deepStrictEqual(inb.json().failures.map((f) => [f.error, f.discord.message_id, f.mapping.space]), [['the thread is locked', locked, 'general']]);
assert.deepStrictEqual(inb.json().failures.map((f) => [f.error, f.discord.message_id, f.mapping.space]), [['the thread is locked', locked, 'general']]);
assert.strictEqual((await call(`/api/v1/relay/inbound/${inb.json().failures[0].id}/dismiss`, { method: 'POST', cookie: adminJwt })).status, 200);
assert.strictEqual((await call(`/api/v1/relay/inbound/${inb.json().failures[0].id}/dismiss`, { method: 'POST', cookie: adminJwt })).status, 200);