/** * Schedules Runner — schedules/crud suite * * Tests schedule CRUD via the kernel schedules API. */ (function () { 'use strict'; var API = window.SR.api; sw.testing.suite('schedules/crud', async function (s) { var schedId; s.test('create schedule', async function (t) { var r = await sw.api.post(API, { name: 'runner-test-' + Date.now(), cron_expr: '0 0 * * *', script: 'print("hello from schedule runner")', enabled: false }); t.assert.ok(r.id, 'schedule has id'); t.assert.ok(r.name, 'schedule has name'); schedId = r.id; s.track('schedule', schedId); }); s.test('get schedule', async function (t) { t.assert.ok(schedId, 'schedId from previous test'); var r = await sw.api.get(API + '/' + schedId); t.assert.eq(r.id, schedId, 'id matches'); t.assert.ok(r.cron_expr, 'cron_expr present'); }); s.test('update schedule', async function (t) { t.assert.ok(schedId, 'schedId from previous test'); var r = await sw.api.put(API + '/' + schedId, { name: 'runner-test-updated', cron_expr: '30 2 * * *' }); t.assert.eq(r.name, 'runner-test-updated', 'name updated'); }); s.test('run schedule', async function (t) { t.assert.ok(schedId, 'schedId from previous test'); try { await sw.api.post(API + '/' + schedId + '/run', {}); t.assert.ok(true, 'run endpoint returned successfully'); } catch (e) { t.warn('Schedule run failed: ' + e.message); } }); s.test('delete schedule', async function (t) { t.assert.ok(schedId, 'schedId from previous test'); await sw.api.del(API + '/' + schedId); try { await sw.api.get(API + '/' + schedId); t.assert.ok(false, 'expected error after delete'); } catch (e) { t.assert.ok(true, 'schedule not found after delete'); } schedId = null; }); }); })();