import { describe, it, expect, csrf } from './runner.js?v=4'; describe('Relay: Push API', () => { it('push without config returns error', async () => { const settings = await fetch('api/relay/settings').then(r => r.json()); // GET only reports `has_key` (boolean) — the secret itself is never // echoed. If a relay is configured the real push may succeed or fail // for other reasons, so skip in that case. if (settings.url && settings.has_key) return; // skip if configured const res = await fetch('api/relay/push', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() }, body: JSON.stringify({ card_id: 1 }), }).then(r => r.json()); expect(res.ok).toBe(false); expect(res.error).toContain('not configured'); }); it('push without card_id returns error', async () => { const settings = await fetch('api/relay/settings').then(r => r.json()); if (!settings.url || !settings.has_key) return; // card_id check is after config check const res = await fetch('api/relay/push', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() }, body: JSON.stringify({}), }); expect(res.status).toBe(400); }); }); describe('Relay: Poll API', () => { it('poll without config returns 0 pulled', async () => { const settings = await fetch('api/relay/settings').then(r => r.json()); if (settings.url && settings.has_key) return; const res = await fetch('api/relay/poll', { method: 'POST', headers: { 'X-CSRF-Token': csrf() }, }).then(r => r.json()); expect(res.ok).toBe(true); expect(res.pulled).toBe(0); }); });