mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
a85a50e186
A ski tour now saves the options its legs were planned with and the piste data build they ran on, as one JSON column (a new migration, since the ski migrations have shipped on this branch); the server keeps only the options its discipline reads. Both stay off every other type. The refusal of a ski time is lifted: the piste router works one out, and the planner sends it only when every leg followed the piste data. get_tour_plan names the legs of a tour the router planned as routed, and list_tours says what the new fields hold.
39 lines
1.9 KiB
TypeScript
39 lines
1.9 KiB
TypeScript
/**
|
|
* `Migration20200101046140_a_ski_tour_keeps_its_piste_router_options` gives a
|
|
* tour one more column, `ski_options`: the JSON text of the piste router's
|
|
* options and the build its legs ran on. Every tour that was there keeps its
|
|
* columns and reads NULL in the new one; the column takes the server's JSON.
|
|
*/
|
|
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const TARGET = 'Migration20200101046140_a_ski_tour_keeps_its_piste_router_options';
|
|
|
|
describe('the ski options column', () => {
|
|
it('TOURSKIOPT-001: adds a nullable column, leaves every tour as it was and takes the JSON the server writes', async () => {
|
|
const orm = await createMigrationOrm();
|
|
try {
|
|
const names = await pendingNames(orm);
|
|
const idx = names.indexOf(TARGET);
|
|
expect(idx).toBeGreaterThan(0);
|
|
await migrateTo(orm, names[idx - 1] as string);
|
|
await rawExec(orm, "INSERT INTO users (id, username, email, password_hash) VALUES (1, 'owner', 'owner@test', 'x')");
|
|
await rawExec(orm, "INSERT INTO trips (id, user_id, title) VALUES (10, 1, 'Alps')");
|
|
await rawExec(orm, "INSERT INTO places (id, trip_id, name) VALUES (100, 10, 'Valley run')");
|
|
await rawExec(orm, "INSERT INTO tours (place_id, tour_type, ski_discipline) VALUES (100, 'ski', 'alpine')");
|
|
|
|
await migrateTo(orm, TARGET);
|
|
|
|
expect(await rawQuery(orm, 'SELECT tour_type, ski_discipline, ski_options FROM tours')).toEqual([
|
|
{ tour_type: 'ski', ski_discipline: 'alpine', ski_options: null },
|
|
]);
|
|
const stored = JSON.stringify({ options: { max_difficulty: 'advanced' }, build: '2026-11-02' });
|
|
await rawExec(orm, 'UPDATE tours SET ski_options = ? WHERE place_id = 100', [stored]);
|
|
expect(await rawQuery(orm, 'SELECT ski_options FROM tours')).toEqual([{ ski_options: stored }]);
|
|
} finally {
|
|
await orm.close(true);
|
|
}
|
|
}, 30000);
|
|
});
|