mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(tours): plan rides on horseback from signposted horse routes
A tour can now be a ride (HOR-01). The planner offers "Horse ride" as a tour type with its own horseshoe, and a Horse routes card beside the waypoints looks, when asked, for the route=horse relations OpenStreetMap knows in the map view. A route opens in a dialog that shows it on a map in the sections it is made of, split at forks, gaps and crossings, so nothing is ever joined across a gap. The rider picks a section and its direction, sees what the horse=* tags along it say (open, limited, closed, or unknown where untagged) and whether it is signposted the other way, and takes it as one undoable step. A section that does not start where the ride ends is only joined by a straight manual stretch once the rider switched that on. Nothing of a ride is routed: every leg follows a section or is drawn by hand, and the waypoint list and the map say which (a section as a solid line with its route, a manual stretch dashed and marked unchecked). A point at a section stays where the route has it, a ride works out no riding time, and distance, heights, day assignment, GPX import and export, the 3D view and the reversed ride keep working with each leg's origin saved and opened again. A failed lookup leaves the ride and the routes already found as they were. The server reads the routes through the shared Overpass client (GET /api/trips/:tripId/tours/horse-routes, Tours addon, trip access), keeps an answer twelve hours per grid-aligned view, and the tour contract refuses a routed leg, a via ferrata or a riding time on a ride and a horse route section on any other type. A migration enables the horse tour type.
This commit is contained in:
@@ -69,6 +69,7 @@ const UNNUMBERED = [
|
||||
'Migration20200101045500_a_hike_can_be_marked_as_a_winter_activity',
|
||||
'Migration20200101045510_a_tour_can_be_a_run',
|
||||
'Migration20200101045520_a_tour_can_be_a_ski_track',
|
||||
'Migration20200101045600_a_tour_can_be_ridden_on_horseback',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* `Migration20200101045600_a_tour_can_be_ridden_on_horseback` (HOR-01):
|
||||
* `tour_types` gains the enabled `horse` key with no routing profile, the
|
||||
* other types stay as they were, and an instance that already defined the key
|
||||
* keeps its own row.
|
||||
*/
|
||||
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
|
||||
import type { MikroORM } from '@mikro-orm/sqlite';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const TARGET = 'Migration20200101045600_a_tour_can_be_ridden_on_horseback';
|
||||
|
||||
async function ormBeforeTarget(): Promise<MikroORM> {
|
||||
const orm = await createMigrationOrm();
|
||||
const names = await pendingNames(orm);
|
||||
const index = names.indexOf(TARGET);
|
||||
expect(index).toBeGreaterThan(0);
|
||||
await migrateTo(orm, names[index - 1]);
|
||||
return orm;
|
||||
}
|
||||
|
||||
describe('Tour horse type migration', () => {
|
||||
it('TOURHORSEMIG-001: adds the enabled horse type without a routing profile and leaves the others alone', async () => {
|
||||
const orm = await ormBeforeTarget();
|
||||
try {
|
||||
const before = await rawQuery(orm, "SELECT key, enabled FROM tour_types WHERE key <> 'horse' ORDER BY key");
|
||||
expect(await rawQuery(orm, "SELECT key FROM tour_types WHERE key = 'horse'")).toEqual([]);
|
||||
|
||||
await migrateTo(orm, TARGET);
|
||||
|
||||
expect(
|
||||
await rawQuery(
|
||||
orm,
|
||||
"SELECT key, label_key, routing_profile, is_sport, enabled, sort_order FROM tour_types WHERE key = 'horse'",
|
||||
),
|
||||
).toEqual([
|
||||
{
|
||||
key: 'horse',
|
||||
label_key: 'tourTypes.horse',
|
||||
routing_profile: null,
|
||||
is_sport: 1,
|
||||
enabled: 1,
|
||||
sort_order: 7,
|
||||
},
|
||||
]);
|
||||
expect(await rawQuery(orm, "SELECT key, enabled FROM tour_types WHERE key <> 'horse' ORDER BY key")).toEqual(
|
||||
before,
|
||||
);
|
||||
} finally {
|
||||
await orm.close(true);
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
it('TOURHORSEMIG-002: a horse type an instance already defined keeps its own values', async () => {
|
||||
const orm = await ormBeforeTarget();
|
||||
try {
|
||||
await rawExec(
|
||||
orm,
|
||||
"INSERT INTO tour_types (key, label_key, icon, color, routing_profile, enabled, sort_order) VALUES ('horse', 'tourTypes.horse', 'Own', '#000000', NULL, 0, 9)",
|
||||
);
|
||||
|
||||
await migrateTo(orm, TARGET);
|
||||
|
||||
expect(await rawQuery(orm, "SELECT icon, enabled, sort_order FROM tour_types WHERE key = 'horse'")).toEqual([
|
||||
{ icon: 'Own', enabled: 0, sort_order: 9 },
|
||||
]);
|
||||
} finally {
|
||||
await orm.close(true);
|
||||
}
|
||||
}, 30000);
|
||||
});
|
||||
@@ -41,7 +41,8 @@ describe('Tour types migration', () => {
|
||||
orm,
|
||||
'SELECT key, enabled, label_key FROM tour_types ORDER BY sort_order',
|
||||
);
|
||||
expect(types.map((t) => t.key)).toEqual([...tourTypeKeySchema.options]);
|
||||
// The keys the contract named then; `horse` came later with a migration of its own (HOR-01).
|
||||
expect(types.map((t) => t.key)).toEqual(tourTypeKeySchema.options.filter((key) => key !== 'horse'));
|
||||
expect(types.filter((t) => t.enabled === 1).map((t) => t.key)).toEqual(['hike']);
|
||||
for (const t of types) expect(t.label_key).toBe(`tourTypes.${t.key}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user