mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 22:31:46 +00:00
56655d53b4
* feat(admin): register AirTrail as an integration addon
Off by default; toggle lives in Admin -> Addons with a Plane icon. The
per-user connection (URL + API key) follows in integration settings.
* feat(integrations): add per-user AirTrail connection
Settings -> Integrations gains an AirTrail section: instance URL + Bearer
API key (encrypted at rest via apiKeyCrypto), a self-signed-TLS opt-in and
a test-connection check. Served by a small Nest controller under
/api/integrations/airtrail, gated on the airtrail addon and SSRF-guarded.
The key is per-user, so it only ever returns that user's own flights.
* feat(transport): import flights from AirTrail
Adds an AirTrail Import button next to Manual Transport that lists the
user's AirTrail flights and highlights the ones inside the trip dates.
Selected flights become reservations linked to their AirTrail origin
(external_* columns), deduped against flights already in the trip, then
broadcast to every member. The mapping resolves airports, airport-local
times and flight metadata; the linkage is what the two-way sync rides on.
* feat(transport): badge AirTrail-linked flights as synced
Linked reservations show an 'AirTrail synced' badge, or 'no longer
synced' once the flight is gone from AirTrail.
* feat(transport): keep TREK and AirTrail flights in sync both ways
A scheduled poll reconciles each connected owner's flights: field edits
(detected by snapshot hash, since AirTrail has no updated_at) flow into
the linked reservation and broadcast live; a flight deleted in AirTrail
keeps the TREK row but stops syncing. Editing a linked flight in TREK
pushes back to AirTrail under the importer's credentials, preserving the
existing seat manifest; if the owner disconnected the link detaches so the
poll can't revert the local edit. Deleting in TREK never touches AirTrail.
* i18n(airtrail): add AirTrail strings across all locales
* test(airtrail): cover flight mapping, timezones and snapshot hashing
* fix(airtrail): reduce airline/aircraft objects to codes
The flight list/get response returns airline and aircraft as joined
objects ({icao, iata, name, ...}), not bare codes. Mapping them straight
through produced '[object Object]' titles and stored objects in metadata,
which crashed reservation rendering. Extract the ICAO/IATA code instead,
and title flights by their flight number.
* fix(airtrail): clear error on non-JSON responses, tolerate /api in URL
A misconfigured instance URL made AirTrail serve its SPA/login HTML, and
the raw JSON.parse failure surfaced as 'Unexpected token <'. Surface an
actionable message instead, and strip a pasted trailing /api so the base
URL still resolves.
* feat(transport): sync AirTrail edits on trip open, not just on the poll
Add a per-user on-demand sync (POST /integrations/airtrail/sync) triggered
when a connected user opens a trip, so AirTrail-side edits appear right away
instead of waiting up to a full poll cycle. Lower the background poll from 15
to 5 minutes as a safety net.
* fix(transport): refresh imported AirTrail flights without a reload
loadTrip doesn't fetch reservations, so a freshly imported flight only
appeared after a full page reload — use loadReservations instead. Also show
flight dates in the user's locale format (e.g. 13.06.2026) rather than the
raw ISO string.
* style(settings): align AirTrail connection with the photo-provider layout
Match the Immich section: stacked URL/key fields, a ToggleSwitch for
self-signed TLS, and a Save / Test-connection row with a status badge.
* feat(transport): add a seat field when editing flights
The transport editor only offered a seat field for trains; flights had
none even though imports store metadata.seat. Show and persist a seat for
flights too.
* style(transport): match the AirTrail button height to Manual Transport
* feat(transport): put the flight seat next to flight number and sync it to AirTrail
Move the seat from a standalone row to the per-leg flight details (beside
the flight number), stored per leg in metadata.legs[].seat with the first
leg mirrored to metadata.seat. On push, set the seat number on the user's
own AirTrail seat (the one with a userId), leaving co-passengers untouched;
import/poll read that same seat back.
* refactor(planner): move the AirTrail trip-open sync into useTripPlanner
Page containers must not own state/effects (lint:pages). Same logic,
relocated from the page into its data hook.
* test(db): pin the region-reconciliation test to its schema version
The test re-ran 'the last migration' assuming the reconciliation is last;
it no longer is once later migrations are appended. Pin to version 135 and
re-run from there (the appended migrations are idempotent).
124 lines
5.3 KiB
TypeScript
124 lines
5.3 KiB
TypeScript
/**
|
|
* Unit test for the Atlas region-code reconciliation migration (#1119).
|
|
*
|
|
* After Atlas swapped Natural Earth for geoBoundaries, manually-marked regions
|
|
* (`visited_regions`) held the old Natural Earth ISO-3166-2 codes. The final migration
|
|
* reconciles each row against the shipped admin-1 bundle: valid codes are kept, codes
|
|
* whose region NAME still matches are re-coded, renamed-merge cases use a curated
|
|
* crosswalk, and anything else is left untouched. We exercise the real migration by
|
|
* running all migrations, seeding rows, rewinding schema_version by one, and re-running
|
|
* so only the last (reconciliation) migration fires.
|
|
*/
|
|
import { describe, it, expect } from 'vitest';
|
|
import Database from 'better-sqlite3';
|
|
import { createTables } from '../../../src/db/schema';
|
|
import { runMigrations } from '../../../src/db/migrations';
|
|
import { createUser } from '../../helpers/factories';
|
|
|
|
function freshDb() {
|
|
const db = new Database(':memory:');
|
|
db.exec('PRAGMA journal_mode = WAL');
|
|
db.exec('PRAGMA foreign_keys = ON');
|
|
createTables(db);
|
|
runMigrations(db);
|
|
return db;
|
|
}
|
|
|
|
function mark(db: Database.Database, userId: number, code: string, name: string, country = 'NO') {
|
|
db.prepare(
|
|
'INSERT INTO visited_regions (user_id, region_code, region_name, country_code) VALUES (?, ?, ?, ?)'
|
|
).run(userId, code, name, country);
|
|
}
|
|
|
|
// The visited_regions reconciliation (#1119) is pinned at schema version 135.
|
|
// Migrations added afterwards are appended AFTER it (append-only), so it is no
|
|
// longer the last migration. Rewind to just before the reconciliation and
|
|
// re-run: the later migrations are idempotent, so only the reconciliation has
|
|
// any effect on the seeded rows here.
|
|
const RECONCILIATION_VERSION = 135;
|
|
function rerunLastMigration(db: Database.Database) {
|
|
db.prepare('UPDATE schema_version SET version = ?').run(RECONCILIATION_VERSION - 1);
|
|
runMigrations(db);
|
|
}
|
|
|
|
describe('Atlas region-code reconciliation migration', () => {
|
|
it('CROSSWALK-001: remaps a renamed-merge county via the curated crosswalk', () => {
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
mark(db, user.id, 'NO-05', 'Oppland'); // merged into Innlandet, name changed
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const rows = db.prepare('SELECT region_code, region_name FROM visited_regions WHERE user_id = ?').all(user.id);
|
|
expect(rows).toEqual([{ region_code: 'NO-34', region_name: 'Innlandet' }]);
|
|
db.close();
|
|
});
|
|
|
|
it('CROSSWALK-002: merges two old counties that map to the same new region (no UNIQUE clash)', () => {
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
mark(db, user.id, 'NO-04', 'Hedmark'); // → Innlandet
|
|
mark(db, user.id, 'NO-05', 'Oppland'); // → Innlandet
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const rows = db.prepare('SELECT region_code FROM visited_regions WHERE user_id = ?').all(user.id);
|
|
expect(rows).toEqual([{ region_code: 'NO-34' }]);
|
|
db.close();
|
|
});
|
|
|
|
it('CROSSWALK-003: leaves a still-valid code untouched', () => {
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
mark(db, user.id, 'NO-03', 'Oslo'); // present in the new bundle
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const rows = db.prepare('SELECT region_code, region_name FROM visited_regions WHERE user_id = ?').all(user.id);
|
|
expect(rows).toEqual([{ region_code: 'NO-03', region_name: 'Oslo' }]);
|
|
db.close();
|
|
});
|
|
|
|
it('CROSSWALK-004: re-codes a stale code whose region NAME still matches the bundle', () => {
|
|
// Not in any crosswalk: a bogus code but a name ("Oslo") that the bundle still carries
|
|
// for NO → reconciled to the bundle's code for that name (NO-03) by the name-match path.
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
mark(db, user.id, 'NO-99', 'Oslo');
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const rows = db.prepare('SELECT region_code, region_name FROM visited_regions WHERE user_id = ?').all(user.id);
|
|
expect(rows).toEqual([{ region_code: 'NO-03', region_name: 'Oslo' }]);
|
|
db.close();
|
|
});
|
|
|
|
it('CROSSWALK-005: leaves an unresolvable row as-is (no code, no name, no crosswalk match)', () => {
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
mark(db, user.id, 'ZZ-99', 'Nowhere', 'ZZ');
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const rows = db.prepare('SELECT region_code, region_name FROM visited_regions WHERE user_id = ?').all(user.id);
|
|
expect(rows).toEqual([{ region_code: 'ZZ-99', region_name: 'Nowhere' }]);
|
|
db.close();
|
|
});
|
|
|
|
it('CROSSWALK-006: does not touch bucket_list or visited_countries (no region identifier there)', () => {
|
|
const db = freshDb();
|
|
const { user } = createUser(db);
|
|
db.prepare('INSERT INTO bucket_list (user_id, name, country_code) VALUES (?, ?, ?)').run(user.id, 'Oppland', 'NO');
|
|
db.prepare('INSERT INTO visited_countries (user_id, country_code) VALUES (?, ?)').run(user.id, 'NO');
|
|
mark(db, user.id, 'NO-05', 'Oppland'); // ensure the migration actually runs its body
|
|
|
|
rerunLastMigration(db);
|
|
|
|
const bucket = db.prepare('SELECT name, country_code FROM bucket_list WHERE user_id = ?').all(user.id);
|
|
expect(bucket).toEqual([{ name: 'Oppland', country_code: 'NO' }]); // free-text name untouched
|
|
const countries = db.prepare('SELECT country_code FROM visited_countries WHERE user_id = ?').all(user.id);
|
|
expect(countries).toEqual([{ country_code: 'NO' }]);
|
|
db.close();
|
|
});
|
|
});
|