Files
hyprcrd/public/plugins/tests/relay.test.js
T
2026-04-12 16:09:34 +02:00

40 lines
1.6 KiB
JavaScript

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());
// The GET endpoint echoes the secret directly as `key` (single-user local app).
if (settings.url && settings.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.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.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);
});
});