Files
TREK/shared/src/flight-live/flight-live.schema.spec.ts
T
Maurice 154563f34d feat(flight-live): follow booked flights live from keyless ADS-B feeds
A new flight-live domain polls the open feeds adsb.lol and adsb.fi (no key,
no cost; adsb.fi only on self-hosted installs, its terms are non-commercial)
for every booked flight leg in its watch window, derives phase, take-off,
landing, delay and an arrival estimate, and pushes changes as flight:live.
GET /api/trips/:tripId/flights/live, the MCP tool get_trip_flight_status,
notifications for take-off, landing and delays, and the admin switch
flight_live_enabled (FLIGHT_LIVE_ENABLED wins) come with it.
2026-11-13 15:29:03 +01:00

52 lines
1.6 KiB
TypeScript

import { flightLiveLegSchema, tripFlightLiveResponseSchema } from './flight-live.schema';
import { describe, it, expect } from 'vitest';
const leg = {
reservation_id: 6,
leg_index: 0,
callsign: 'DLH400',
flight_number: 'LH 400',
service_date: '2026-06-11',
origin: { code: 'FRA', name: 'Frankfurt', lat: 50.03, lng: 8.57, timezone: 'Europe/Berlin' },
destination: { code: 'JFK', name: 'New York JFK', lat: 40.64, lng: -73.78, timezone: 'America/New_York' },
phase: 'scheduled',
scheduled_departure: '2026-06-11T11:50:00.000Z',
scheduled_arrival: '2026-06-11T20:35:00.000Z',
departed_at: null,
landed_at: null,
estimated_arrival: null,
departure_delay_min: null,
arrival_delay_min: null,
progress: null,
distance_total_km: 6200,
distance_remaining_km: null,
position: null,
aircraft: null,
last_seen_at: null,
fetched_at: null,
stale: false,
source: null,
};
describe('flightLiveLegSchema', () => {
it('accepts a leg that has not shown up yet', () => {
expect(flightLiveLegSchema.parse(leg).phase).toBe('scheduled');
});
it('rejects a progress outside 0 to 1', () => {
expect(flightLiveLegSchema.safeParse({ ...leg, progress: 1.2 }).success).toBe(false);
});
it('rejects an unknown phase', () => {
expect(flightLiveLegSchema.safeParse({ ...leg, phase: 'boarding' }).success).toBe(false);
});
});
describe('tripFlightLiveResponseSchema', () => {
it('carries the switch, the credit line and the legs', () => {
const parsed = tripFlightLiveResponseSchema.parse({ enabled: true, attribution: 'adsb.lol', flights: [leg] });
expect(parsed.flights).toHaveLength(1);
});
});