Files
pulse-signage/test/data-admin.test.js
T
lzstealth b71958cb38
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile, web, pulse-signage-web) (push) Successful in 1m21s
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile.player, player, pulse-signage-player) (push) Successful in 32s
Release 2.22.0: normalize playlist schedules and unify player sync
2026-10-27 22:54:38 +00:00

51 lines
2.2 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const { fetchAdminData, fetchSlidesPage } = require('../src/data/admin');
test('slide search does not include slide content_json', async () => {
const queries = [];
const pool = {
async query(sql, params) {
queries.push({ sql, params });
if (sql.startsWith('SELECT COUNT(*)')) {
return [[{ count: 0 }]];
}
return [[{ id: 1 }]];
}
};
await fetchSlidesPage(pool, 1, 25, 'hello world', 'title', 'asc');
assert.equal(queries.length, 2);
assert.doesNotMatch(queries[0].sql, /CAST\(s\.content_json AS CHAR\)/);
assert.doesNotMatch(queries[1].sql, /CAST\(s\.content_json AS CHAR\)/);
assert.match(queries[0].sql, /CAST\(s\.title AS CHAR\)/);
assert.match(queries[0].sql, /CAST\(st\.name AS CHAR\)/);
});
test('admin playlist data attaches normalized slide and group rules by owner ID', async () => {
const pool = {
async query(sql) {
if (sql.includes('FROM c_playlist_slides ps')) {
return [[
{ id: 12, playlist_id: 3, slide_id: 22, group_id: 5, group_key: 'events', group_name: 'Events', group_pick_count: 1, group_shuffle: 0, group_mode: 'select', group_repeat_count: 1 },
{ id: 13, playlist_id: 3, slide_id: 23, group_id: 5, group_key: 'events', group_name: 'Events', group_pick_count: 1, group_shuffle: 0, group_mode: 'select', group_repeat_count: 1 }
]];
}
if (sql.includes('FROM c_playlist_schedule_rules')) {
return [[
{ id: 70, playlist_slide_id: 12, playlist_group_id: null, start_datetime: '2026-10-01 09:00:00', end_datetime: null, schedule_days_json: null },
{ id: 71, playlist_slide_id: null, playlist_group_id: 5, start_datetime: null, end_datetime: '2026-10-31 18:00:00', schedule_days_json: '[3]' }
]];
}
return [[]];
}
};
const data = await fetchAdminData(pool);
assert.equal(data.playlistSlides[0].scheduleRules[0].id, 70);
assert.equal(data.playlistSlides[0].groupScheduleRules[0].id, 71);
assert.equal(data.playlistSlides[1].scheduleRules.length, 0);
assert.equal(data.playlistSlides[1].groupScheduleRules[0].id, 71);
});