mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
04d134755a
- GET /api/addons/atlas/flights folds the user's flight bookings into routes, airports and totals for the globe's arcs (#1369, #2642). - GET /api/addons/atlas/people answers the Atlas side of other travellers on the instance: counts, visited countries and earned badges, never trips, places or dates. A user hides themselves with the atlas_hidden setting; the admin switch atlas_compare_enabled turns it off for all. - shared/src/atlas/atlas-badges.ts holds the badge rules, computed from the data a user already has, so nothing is stored. - MCP: list_atlas_flight_routes, list_atlas_badges, list_atlas_travellers.
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { aggregateFlights, greatCircleKm } from '../../../src/nest/atlas/atlas-flights.service';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const FRA = { code: 'FRA', name: 'Frankfurt', lat: 50.033, lng: 8.57 };
|
|
const JFK = { code: 'JFK', name: 'New York JFK', lat: 40.641, lng: -73.778 };
|
|
const SFO = { code: 'SFO', name: 'San Francisco', lat: 37.621, lng: -122.379 };
|
|
|
|
function leg(reservation_id: number, a: typeof FRA, b: typeof FRA, date: string | null = null) {
|
|
return [
|
|
{ reservation_id, ...a, local_date: date },
|
|
{ reservation_id, ...b, local_date: null },
|
|
];
|
|
}
|
|
|
|
describe('atlas flight map', () => {
|
|
it('measures great circles in kilometres', () => {
|
|
expect(greatCircleKm(FRA, JFK)).toBeGreaterThan(6100);
|
|
expect(greatCircleKm(FRA, JFK)).toBeLessThan(6300);
|
|
expect(greatCircleKm(FRA, FRA)).toBe(0);
|
|
});
|
|
|
|
it('folds both directions of a route into one with a count and its dates', () => {
|
|
const r = aggregateFlights([
|
|
...leg(1, FRA, JFK, '2018-05-01'),
|
|
...leg(2, JFK, FRA, '2019-02-03'),
|
|
...leg(3, FRA, JFK, '2017-01-01'),
|
|
]);
|
|
expect(r.routes).toHaveLength(1);
|
|
expect(r.routes[0]).toMatchObject({ count: 3, firstDate: '2017-01-01', lastDate: '2019-02-03' });
|
|
expect(r.totals.flights).toBe(3);
|
|
expect(r.airports.find((a) => a.code === 'FRA')?.count).toBe(3);
|
|
});
|
|
|
|
it('makes one leg per consecutive pair inside a booking, never across bookings', () => {
|
|
const rows = [
|
|
{ reservation_id: 7, ...FRA, local_date: null },
|
|
{ reservation_id: 7, ...JFK, local_date: null },
|
|
{ reservation_id: 7, ...SFO, local_date: null },
|
|
{ reservation_id: 8, ...FRA, local_date: null },
|
|
];
|
|
const r = aggregateFlights(rows);
|
|
expect(r.totals.flights).toBe(2);
|
|
expect(r.routes.map((x) => `${x.a.code}-${x.b.code}`).sort()).toEqual(['FRA-JFK', 'JFK-SFO']);
|
|
expect(r.totals.longestKm).toBe(Math.round(greatCircleKm(FRA, JFK)));
|
|
});
|
|
|
|
it('skips a leg that lands where it started', () => {
|
|
expect(aggregateFlights(leg(1, FRA, FRA)).totals.flights).toBe(0);
|
|
});
|
|
});
|