Files
ridebus-admin/backend/test/alertSchedulerService.test.js
Zakhar Timoshenko 595ad6456b feat: add schedule import functionality and quality control page
- Implemented the schedule import feature with a dedicated page for importing schedules from the transport website.
- Added a new QualityPage to check the quality of routes, stops, schedules, and notifications without making automatic changes.
- Created CSS styles for both the ScheduleImportPage and QualityPage to enhance the user interface.
- Introduced API calls for fetching schedule data and quality reports.
- Added error handling and loading states for better user experience during data fetching.
- Included functionality for filtering quality issues and displaying detailed reports.
2026-09-16 21:55:50 +03:00

58 lines
1.9 KiB
JavaScript

const assert = require('node:assert/strict');
const test = require('node:test');
const { AlertSchedulerService } = require('../src/services/alertSchedulerService');
function createLogger() {
return { error() {} };
}
test('scheduled delivery claims a due alert, sends it, then records delivery', async () => {
const calls = [];
const pool = {
async query(sql, params = []) {
const normalized = String(sql).replace(/\s+/g, ' ').trim();
calls.push({ normalized, params });
if (normalized.startsWith('WITH due AS')) {
return { rows: [{
id: 17, route_id: 3, route_number: '4', notification_route_number: '4',
alert_type: 'detour', title: 'Объезд', message: 'Через центр',
start_time: new Date(), end_time: null, is_active: true
}] };
}
return { rows: [] };
}
};
const notifications = [];
const service = new AlertSchedulerService({
pool,
notificationService: {
enabled: true,
async sendAlertCreated(alert) {
notifications.push(alert);
return { sent: true, messageId: 'test-message' };
}
},
logger: createLogger()
});
const result = await service.dispatchDueAlerts();
assert.deepEqual(result, { dispatched: 1, claimed: 1 });
assert.equal(notifications.length, 1);
assert.equal(notifications[0].route_number, '4');
assert.equal(calls.length, 2);
assert.match(calls[1].normalized, /^UPDATE alerts SET notification_sent_at/);
});
test('scheduler leaves the database untouched while notifications are disabled', async () => {
let queries = 0;
const service = new AlertSchedulerService({
pool: { async query() { queries += 1; return { rows: [] }; } },
notificationService: { enabled: false },
logger: createLogger()
});
assert.deepEqual(await service.dispatchDueAlerts(), { dispatched: 0, skipped: 'disabled' });
assert.equal(queries, 0);
});