feat: implement stop alias management for Telegram import
- Added TelegramStopAliasService for handling stop aliases in the database. - Created API endpoints for managing stop aliases (list, create, update, delete). - Introduced TelegramStopAliases component in the frontend for user interaction with stop aliases. - Updated TelegramImportService to utilize stop aliases for message processing. - Enhanced telegramCancellationParser to resolve stop names using aliases. - Added migration script to create telegram_stop_aliases table and seed initial data. - Updated documentation to include details about stop alias functionality.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { parseCancellation, matchCancellationRoutes, buildCancellationAlert, dayBounds } = require('../src/services/telegramCancellationParser');
|
||||
const { parseCancellation, resolveCancellationStops, matchCancellationRoutes, buildCancellationAlert, normalizeStopKey, dayBounds } = require('../src/services/telegramCancellationParser');
|
||||
|
||||
const text = `Уважаемые пассажиры!
|
||||
Не будут выполняться рейсы:
|
||||
@@ -87,3 +87,31 @@ test('midnight expiry is an explicit UTC instant, including year boundary', () =
|
||||
});
|
||||
|
||||
module.exports = { carrierText: text };
|
||||
|
||||
test('dictionary selects the actual stop ID and uses its canonical name in concise alerts', () => {
|
||||
const stops = [{ id: 11, name: 'Автовокзал' }, { id: 22, name: 'Зодчего Иоанна' }, { id: 23, name: 'Зодчего Иоанна' }];
|
||||
const aliases = [{ normalized_alias: normalizeStopKey('ЗОДЧЕГО'), stop_id: 22 }];
|
||||
const parsed = resolveCancellationStops(parse(), stops, aliases);
|
||||
const routes = [
|
||||
{ id: 1, route_number: '27', origin_stop_id: 11, origin_stop: 'Автовокзал' },
|
||||
{ id: 2, route_number: '27', origin_stop_id: 22, origin_stop: 'Зодчего Иоанна' },
|
||||
{ id: 3, route_number: '27', origin_stop_id: 23, origin_stop: 'Зодчего Иоанна' }
|
||||
];
|
||||
const matched = matchCancellationRoutes(parsed, routes);
|
||||
assert.deepEqual(matched.plans.map(plan => plan.routeId), [1, 2]);
|
||||
const alert = buildCancellationAlert(matched.plans[1], '2026-10-02', 'https://t.me/avp2Polotsk/1166', '2026-10-02T12:52Z', 1);
|
||||
assert.equal(alert.message, '02.10.2026: не выполняются рейсы:\nЗодчего Иоанна — 15:58, 16:58\nИсточник: https://t.me/avp2Polotsk/1166');
|
||||
assert.doesNotMatch(alert.message, /Уважаемые|С УВАЖЕНИЕМ/);
|
||||
assert.equal(normalizeStopKey(' « ЗОД-ЧЕГО » '), normalizeStopKey('Зодчего'));
|
||||
});
|
||||
|
||||
test('canonical names are taken from the catalog; inactive aliases and ambiguous platforms require review', () => {
|
||||
const parsed = parse(text.replace('ЗОДЧЕГО', 'ЗОДЧЕГО ИОАННА'));
|
||||
const stops = [{ id: 11, name: 'Автовокзал' }, { id: 22, name: 'Зодчего Иоанна' }];
|
||||
assert.equal(resolveCancellationStops(parsed, stops, []).groups[0].departures[1].stop, 'Зодчего Иоанна');
|
||||
const inactive = resolveCancellationStops(parse(), [stops[0]], [{ normalized_alias: 'зодчего', stop_id: 22 }]);
|
||||
assert.match(matchCancellationRoutes(inactive, [{ id: 1, route_number: '27' }]).reasons[0], /отключена/);
|
||||
const ambiguous = resolveCancellationStops(parsed, [...stops, { id: 23, name: 'Зодчего Иоанна' }], []);
|
||||
const result = matchCancellationRoutes(ambiguous, [{ id: 1, route_number: '27', origin_stop: 'Зодчего Иоанна' }, { id: 2, route_number: '27', origin_stop: 'Зодчего Иоанна' }]);
|
||||
assert.equal(result.plans.length, 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user