feat: enhance cancellation parser to support mixed wording and add tests for hospital cancellations
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { parseCancellation, resolveCancellationStops, matchCancellationRoutes, buildCancellationAlert, normalizeStopKey, dayBounds } = require('../src/services/telegramCancellationParser');
|
||||
const hospitalText = fs.readFileSync(path.join(__dirname, 'fixtures/telegram-hospital-cancellation.txt'), 'utf8');
|
||||
|
||||
const text = `Уважаемые пассажиры!
|
||||
Не будут выполняться рейсы:
|
||||
@@ -35,6 +38,31 @@ test('09.10 in a departure list remains a time', () => {
|
||||
assert.deepEqual(parse(text.replace('15.43', '09.10')).groups[0].departures[0].times, ['09:10', '16:43']);
|
||||
});
|
||||
|
||||
test('hospital post with ОТ ОСТАНОВКИ preserves all four times and uses the publication date', () => {
|
||||
const result = parse(hospitalText, '2026-10-05T04:16:53Z');
|
||||
assert.equal(result.status, 'ready');
|
||||
assert.equal(result.serviceDate, '2026-10-05');
|
||||
assert.equal(result.inferredDate, true);
|
||||
assert.deepEqual(result.groups, [{ routeNumber: '2', departures: [
|
||||
{ stop: 'больница ксты', times: ['07:15', '08:45'] },
|
||||
{ stop: 'больница(новка)', times: ['08:00', '09:30'] }
|
||||
] }]);
|
||||
assert.equal(dayBounds(result.serviceDate).end, '2026-10-05T21:00:00.000Z');
|
||||
});
|
||||
|
||||
test('с/от wording may be mixed; real dates and invalid times remain validated', () => {
|
||||
for (const prefix of ['На 06.10\n', '06.10.2026\n', 'Завтра\n']) {
|
||||
const result = parse(prefix + hospitalText.replace('ОТ ОСТАНОВКИ', 'с остановки'), '2026-10-05T04:16:53Z');
|
||||
assert.equal(result.status, 'ready', prefix);
|
||||
assert.equal(result.serviceDate, '2026-10-06', prefix);
|
||||
}
|
||||
const invalidDate = parse('На 31.02.2026\n' + hospitalText, '2026-10-05T04:16:53Z');
|
||||
assert.deepEqual(invalidDate.reasons, ['Некорректная дата отмены.']);
|
||||
const invalidTime = parse(hospitalText.replace('7.15', '25.15'), '2026-10-05T04:16:53Z');
|
||||
assert.deepEqual(invalidTime.reasons, ['Некорректное время отправления.']);
|
||||
assert.deepEqual(parse(text.replace('15.43', '09.10').replace(/С ОСТАНОВКИ/g, 'ОТ ОСТАНОВКИ')).groups[0].departures[0].times, ['09:10', '16:43']);
|
||||
});
|
||||
|
||||
test('ambiguous dates, conditions, invalid times and unspecified departures require review', () => {
|
||||
for (const value of [
|
||||
'Сегодня и завтра\n' + text, 'На 31.02.2026\n' + text,
|
||||
|
||||
Reference in New Issue
Block a user