openvibers/openvibe.community Commits
Wait for the async inbound failure before asserting it in relay test (#6)
Changes
@@@ -319,6 +319,8 @@ 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 });assert.strictEqual(inb.status, 200);
@@ -319,6 +319,8 @@ const sent = (gw, op) => gw.sockets.flatMap((s) => s.sent).filter((p) => p.op ==
@@ -319,6 +319,8 @@ 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 });
const inb = await call('/api/v1/relay/inbound', { cookie: adminJwt });
assert.strictEqual(inb.status, 200);
assert.strictEqual(inb.status, 200);