mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
feat(atlas): show the most recently visited countries first on the dashboard (#2648)
The place and endpoint reads behind the passport tile now carry the last day of each started trip, and getTravelStats orders the countries by their latest visit, with countries only marked by hand after them. The country set is unchanged; repository, parity and service tests pin the order.
This commit is contained in:
@@ -166,11 +166,26 @@ describe('PlaceRegionsRepository.listStartedTripPlaceCountriesForUser (AT44)', (
|
||||
|
||||
const today = '2026-01-01';
|
||||
const expected = [
|
||||
{ id: cached.id, lat: 48.85, lng: 2.35, address: null, country_code: 'FR' },
|
||||
{ id: uncached.id, lat: 41.9022, lng: 12.4539, address: null, country_code: null },
|
||||
{ id: cached.id, lat: 48.85, lng: 2.35, address: null, country_code: 'FR', trip_last_date: '2020-01-10' },
|
||||
{ id: uncached.id, lat: 41.9022, lng: 12.4539, address: null, country_code: null, trip_last_date: '2020-01-10' },
|
||||
];
|
||||
expect(await repo.listStartedTripPlaceCountriesForUser(owner.id, today)).toEqual(expected);
|
||||
expect(await repo.listStartedTripPlaceCountriesForUser(member.id, today)).toEqual(expected);
|
||||
expect(await repo.listStartedTripPlaceCountriesForUser(stranger.id, today)).toEqual([]);
|
||||
});
|
||||
|
||||
it('PLACEREGREPO-010: dates each place by its own trip, the start standing in for a missing end (#2648)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const ended = createTrip(testDb, user.id, { start_date: '2020-01-01', end_date: '2020-01-10' });
|
||||
const openEnded = createTrip(testDb, user.id, { start_date: '2021-07-01' });
|
||||
const first = createPlace(testDb, ended.id);
|
||||
const second = createPlace(testDb, openEnded.id);
|
||||
|
||||
const rows = await repo.listStartedTripPlaceCountriesForUser(user.id, '2026-01-01');
|
||||
|
||||
expect(rows.map((row) => [row.id, row.trip_last_date])).toEqual([
|
||||
[first.id, '2020-01-10'],
|
||||
[second.id, '2021-07-01'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,13 +41,15 @@ const AT6 = (n: number) => `
|
||||
WHERE r.trip_id IN (${Array(n).fill('?').join(',')}) AND e.role IN ('from', 'to')
|
||||
AND ${TRAVELER_OWNS}`;
|
||||
|
||||
// AT45 also names the trip's last day since #2648, the dashboard's order of countries.
|
||||
const AT45 = `
|
||||
SELECT DISTINCT e.id, e.reservation_id, r.trip_id, e.role, e.code, e.lat, e.lng, e.local_date, e.local_time,
|
||||
r.type AS reservation_type, r.status AS reservation_status,
|
||||
CASE e.role
|
||||
WHEN 'to' THEN COALESCE(r.reservation_end_time, r.reservation_time)
|
||||
ELSE COALESCE(r.reservation_time, r.reservation_end_time)
|
||||
END AS fallback_time
|
||||
END AS fallback_time,
|
||||
COALESCE(t.end_date, t.start_date) AS trip_last_date
|
||||
FROM reservation_endpoints e
|
||||
JOIN reservations r ON e.reservation_id = r.id
|
||||
JOIN trips t ON r.trip_id = t.id
|
||||
|
||||
@@ -509,3 +509,71 @@ describe('personal figures on a shared trip (#1966)', () => {
|
||||
expect(a.totalDistanceKm).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── The order of the passport card's countries (#2648) ──────────────────────
|
||||
|
||||
describe('getTravelStats country order (#2648)', () => {
|
||||
async function placeIn(tripId: number, lat: number, lng: number) {
|
||||
await insertRow(await sharedTestOrm(testDb), Places, { trip: tripId, name: 'Stop' }, { lat, lng });
|
||||
}
|
||||
|
||||
async function markByHand(userId: number, code: string) {
|
||||
await insertRow(await sharedTestOrm(testDb), VisitedCountries, { user: userId, country_code: code });
|
||||
}
|
||||
|
||||
it('lists the countries of the latest trip first, whatever the alphabet says', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const austria = createTrip(testDb, user.id, { title: 'Vienna', start_date: '2022-03-01', end_date: '2022-03-05' });
|
||||
const japan = createTrip(testDb, user.id, { title: 'Tokyo', start_date: '2024-10-01', end_date: '2024-10-12' });
|
||||
const france = createTrip(testDb, user.id, { title: 'Paris', start_date: '2023-06-01', end_date: '2023-06-04' });
|
||||
await placeIn(austria.id, 48.2082, 16.3738);
|
||||
await placeIn(japan.id, 35.6762, 139.6503);
|
||||
await placeIn(france.id, 48.8606, 2.3376);
|
||||
|
||||
expect((await atlas.getTravelStats(user.id)).countries).toEqual(['JP', 'FR', 'AT']);
|
||||
});
|
||||
|
||||
it('dates a country by its most recent visit, places and bookings alike', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const early = createTrip(testDb, user.id, { title: 'Paris', start_date: '2021-05-01', end_date: '2021-05-03' });
|
||||
const middle = createTrip(testDb, user.id, { title: 'Rome', start_date: '2022-05-01', end_date: '2022-05-03' });
|
||||
const late = createTrip(testDb, user.id, {
|
||||
title: 'Back to France',
|
||||
start_date: '2023-05-01',
|
||||
end_date: '2023-05-03',
|
||||
});
|
||||
await placeIn(early.id, 48.8606, 2.3376);
|
||||
await placeIn(middle.id, 41.8902, 12.4922);
|
||||
// The return to France is a booking only: its arrival dates FR again, after Rome.
|
||||
const flight = createReservation(testDb, late.id, { type: 'flight' });
|
||||
await makeReservationEndpoint(await sharedTestOrm(testDb), flight.id, {
|
||||
role: 'to',
|
||||
sequence: 1,
|
||||
name: 'Paris',
|
||||
lat: 49.0097,
|
||||
lng: 2.5479,
|
||||
});
|
||||
|
||||
expect((await atlas.getTravelStats(user.id)).countries).toEqual(['FR', 'IT']);
|
||||
});
|
||||
|
||||
it('puts a country only marked by hand after every country a trip reached', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await markByHand(user.id, 'NZ');
|
||||
const trip = createTrip(testDb, user.id, { title: 'Paris', start_date: '2023-06-01', end_date: '2023-06-04' });
|
||||
await placeIn(trip.id, 48.8606, 2.3376);
|
||||
|
||||
expect((await atlas.getTravelStats(user.id)).countries).toEqual(['FR', 'NZ']);
|
||||
});
|
||||
|
||||
it('lists a country both marked by hand and reached by a trip once, by the trip', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await markByHand(user.id, 'AT');
|
||||
const austria = createTrip(testDb, user.id, { title: 'Vienna', start_date: '2024-03-01', end_date: '2024-03-05' });
|
||||
const france = createTrip(testDb, user.id, { title: 'Paris', start_date: '2023-06-01', end_date: '2023-06-04' });
|
||||
await placeIn(austria.id, 48.2082, 16.3738);
|
||||
await placeIn(france.id, 48.8606, 2.3376);
|
||||
|
||||
expect((await atlas.getTravelStats(user.id)).countries).toEqual(['AT', 'FR']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user