mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
382ba79584
A visit is a place planned on a day of one of the reader's trips; nothing is kept or confirmed by hand. A place keeps a log of changes to its details, links the tours and bookings it is about, and carries tags private to the reader, which a copy into a trip takes along only when picked. Contracts, routes, MCP tools and migrations for both engines.
124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import {
|
|
placeActivitiesResponseSchema,
|
|
placeActivityCandidatesResponseSchema,
|
|
placeLibraryActivitiesRequestSchema,
|
|
placeLibraryActivitiesResponseSchema,
|
|
savedPlaceActivityLinkRequestSchema,
|
|
tripPlaceActivityLinkRequestSchema,
|
|
} from './place-activities.schema';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const booking = {
|
|
key: 'reservation:4',
|
|
type: 'booking',
|
|
origin: { kind: 'trip', trip_id: 1, trip_title: 'Rome' },
|
|
target: { kind: 'reservation', trip_id: 1, reservation_id: 4 },
|
|
title: 'Colosseum guided tour',
|
|
booking_type: 'tour',
|
|
booking_status: 'confirmed',
|
|
tour_type: null,
|
|
starts_at: '2026-05-02T10:00',
|
|
ends_at: null,
|
|
date: '2026-05-02',
|
|
day_number: 2,
|
|
};
|
|
|
|
describe('place activity contracts (PLC-18)', () => {
|
|
it('links exactly one booking or tour of the trip', () => {
|
|
expect(tripPlaceActivityLinkRequestSchema.parse({ reservation_id: 4 })).toEqual({ reservation_id: 4 });
|
|
expect(tripPlaceActivityLinkRequestSchema.parse({ tour_id: 9 })).toEqual({ tour_id: 9 });
|
|
for (const body of [
|
|
{},
|
|
{ reservation_id: 4, tour_id: 9 },
|
|
{ reservation_id: '4' },
|
|
{ tour_id: 0 },
|
|
{ tour_id: 1.5 },
|
|
{ reservation_id: 4, x: 1 },
|
|
]) {
|
|
expect(tripPlaceActivityLinkRequestSchema.safeParse(body).success).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('links one kept tour of the list', () => {
|
|
expect(savedPlaceActivityLinkRequestSchema.parse({ collection_tour_id: 3 })).toEqual({ collection_tour_id: 3 });
|
|
for (const body of [{}, { collection_tour_id: '3' }, { collection_tour_id: -1 }, { collection_tour_id: 3, y: 2 }]) {
|
|
expect(savedPlaceActivityLinkRequestSchema.safeParse(body).success).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('describes the activities of a place, linked and implicit', () => {
|
|
const response = {
|
|
activities: [
|
|
{
|
|
...booking,
|
|
source: { kind: 'trip', trip_id: 1, place_id: 7 },
|
|
explicit: false,
|
|
implicit_via: 'place',
|
|
can_unlink: false,
|
|
},
|
|
{
|
|
...booking,
|
|
key: 'tour:12',
|
|
type: 'tour',
|
|
target: { kind: 'tour', trip_id: 1, tour_id: 12 },
|
|
title: 'City walk',
|
|
booking_type: null,
|
|
booking_status: null,
|
|
tour_type: 'walk',
|
|
starts_at: null,
|
|
source: { kind: 'trip', trip_id: 1, place_id: 7 },
|
|
explicit: true,
|
|
implicit_via: null,
|
|
can_unlink: true,
|
|
},
|
|
],
|
|
can_link: true,
|
|
};
|
|
expect(placeActivitiesResponseSchema.parse(response)).toEqual(response);
|
|
const wrongVia = { ...response, activities: [{ ...response.activities[0], implicit_via: 'other' }] };
|
|
expect(placeActivitiesResponseSchema.safeParse(wrongVia).success).toBe(false);
|
|
});
|
|
|
|
it('describes the candidates and the activities of an entry of All places', () => {
|
|
expect(placeActivityCandidatesResponseSchema.parse({ candidates: [booking] })).toEqual({ candidates: [booking] });
|
|
const kept = {
|
|
...booking,
|
|
key: 'collection_tour:5',
|
|
type: 'tour',
|
|
origin: { kind: 'list', collection_id: 2, collection_name: 'Hikes' },
|
|
target: { kind: 'collection_tour', collection_id: 2, collection_tour_id: 5 },
|
|
source: { kind: 'list', collection_id: 2, collection_place_id: 8 },
|
|
explicit: true,
|
|
implicit_via: null,
|
|
can_unlink: false,
|
|
};
|
|
const library = {
|
|
activities: [kept],
|
|
sources: [
|
|
{
|
|
source: { kind: 'list', collection_id: 2, collection_place_id: 8 },
|
|
origin: { kind: 'list', collection_id: 2, collection_name: 'Hikes' },
|
|
can_link: false,
|
|
},
|
|
],
|
|
};
|
|
expect(placeLibraryActivitiesResponseSchema.parse(library)).toEqual(library);
|
|
expect(
|
|
placeLibraryActivitiesResponseSchema.safeParse({ ...library, sources: [{ source: { kind: 'x' } }] }).success,
|
|
).toBe(false);
|
|
});
|
|
|
|
it('reads an entry of All places from a trip place or a saved place', () => {
|
|
expect(placeLibraryActivitiesRequestSchema.parse({ kind: 'list', id: 8 })).toEqual({ kind: 'list', id: 8 });
|
|
for (const body of [
|
|
{ kind: 'own', id: 8 },
|
|
{ kind: 'trip' },
|
|
{ kind: 'trip', id: '8' },
|
|
{ kind: 'trip', id: 8, z: 1 },
|
|
]) {
|
|
expect(placeLibraryActivitiesRequestSchema.safeParse(body).success).toBe(false);
|
|
}
|
|
});
|
|
});
|