Files
TREK/server/tests/unit/db/known-migrations.test.ts
T
elmocito 57ea219a43 feat(tours): complete planner follow-up scope
This commit completes the reviewed Tours follow-up scope after the Tours MVP was merged into dev.

Included feature blocks:

- RC-01: identify Tours in PLAN day rows and show compact Tour facts;
- RC-06: search for a city or address in TOUR-PLANNER without hidden writes;
- RC-07: reorder Tour waypoints in the left sidebar;
- RC-08: drag Tour waypoints on Leaflet, MapLibre and Mapbox with stable viewport, history and routing behavior;
- RS-01: persist Tour descriptions and HTTPS information links with local provider classification;
- RS-02: persist breaks/additional time and calculated or manually adjusted planned Tour duration without changing scheduling semantics.
The implementation preserves:

- ordinary Place and Legacy Track behavior;
- Tours-off fallback behavior;
- existing GPX/import behavior;
- Tour assignment and deletion behavior;
- calculated routing duration as a separate value;
- existing Tour provenance fields;
- keyboard/list alternatives for waypoint editing.
Not included:

- PR1-09 trip-wide Tour summary;
- Wanderer integration;
- GPX import changes;
- new Tour types;
- Tour-to-Day drag-and-drop;
- further roadmap or Post-Release features.
Validation:

- focused RC-01/RC-06/RC-07/RC-08/RS-01/RS-02 tests passed;
- affected shared/server/client typechecks passed;
- migration and generated DB type checks passed;
- scoped ESLint passed;
- staged diff checks passed;
- owner manual tests passed for all six feature blocks.
2026-10-14 08:39:31 +02:00

44 lines
2.0 KiB
TypeScript

import { knownMigrationNames, unknownMigrations } from '../../../src/db/known-migrations';
import { refuseNewerDatabase } from '../../../src/db/legacy-baseline';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
describe('known migrations', () => {
it('KNOWNMIG-001: lists every migration this build ships, by its recorded name', () => {
const known = knownMigrationNames();
expect(known.has('Migration20200101000000_baseline_schema')).toBe(true);
expect(known.has('Migration20200101042000_tours')).toBe(true);
expect(known.has('Migration20200101042900_tour_planned_total_duration')).toBe(true);
expect(known.has('Migration20200101043000_tour_break_additional_duration')).toBe(true);
expect(known.size).toBe(fs.readdirSync(path.join(__dirname, '../../../src/db/migrations')).length);
});
it('KNOWNMIG-002: reads compiled files too, and ignores maps, declarations and strangers', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'trek-known-migrations-'));
try {
for (const file of [
'Migration20200101000000_a.js',
'Migration20200101000000_a.js.map',
'Migration20200101000100_b.d.ts',
'README.md',
]) {
fs.writeFileSync(path.join(dir, file), '');
}
expect([...knownMigrationNames(dir)]).toEqual(['Migration20200101000000_a']);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
it('KNOWNMIG-003: names only what this build does not ship, and refuses on it', () => {
const known = new Set(['Migration1_a', 'Migration2_b']);
expect(unknownMigrations(['Migration1_a', 'Migration3_c'], known)).toEqual(['Migration3_c']);
expect(() => refuseNewerDatabase(['Migration1_a', 'Migration2_b'], known)).not.toThrow();
expect(() => refuseNewerDatabase(['Migration1_a', 'Migration3_c'], known)).toThrow(/newer TREK/);
expect(() => refuseNewerDatabase(['Migration1_a', 'Migration3_c'], known)).toThrow(/or by a development build/);
});
});