mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { isTravelBooking, travelOnly, withoutImages } from '../../../src/nest/share/share-view.helpers';
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
const snapshot = () => ({
|
|
assignments: {
|
|
1: [
|
|
{ accommodation_id: null, place: { id: 10, image_url: 'a.jpg' } },
|
|
{ accommodation_id: 5, place: { id: 20, image_url: 'b.jpg' } },
|
|
],
|
|
2: [{ accommodation_id: null, place: { id: 10, image_url: 'a.jpg' } }],
|
|
},
|
|
dayNotes: { 1: [{ id: 1 }] },
|
|
places: [
|
|
{ id: 10, image_url: 'a.jpg' },
|
|
{ id: 20, image_url: 'b.jpg' },
|
|
],
|
|
reservations: [{ type: 'flight' }, { type: 'restaurant' }, { type: 'hotel' }, { type: 'cable_car' }, { type: null }],
|
|
});
|
|
|
|
describe('share view helpers (#1712)', () => {
|
|
it('SHARE-VIEW-001: knows travel bookings from the rest', () => {
|
|
expect(['flight', 'train', 'ferry', 'cable_car', 'hotel'].every(isTravelBooking)).toBe(true);
|
|
expect(['restaurant', 'tour', 'event', 'parking', undefined, 3].some(isTravelBooking)).toBe(false);
|
|
});
|
|
|
|
it('SHARE-VIEW-002: travel only keeps the stay stops, the stay places and the travel bookings', () => {
|
|
const out = travelOnly(snapshot(), new Set([20]));
|
|
expect(out.assignments).toEqual({ 1: [{ accommodation_id: 5, place: { id: 20, image_url: 'b.jpg' } }] });
|
|
expect(out.dayNotes).toEqual({});
|
|
expect(out.places.map((p) => p.id)).toEqual([20]);
|
|
expect(out.reservations.map((r) => r.type)).toEqual(['flight', 'hotel', 'cable_car']);
|
|
});
|
|
|
|
it('SHARE-VIEW-003: without images clears every photo and leaves the rest alone', () => {
|
|
const data = snapshot();
|
|
const out = withoutImages(data);
|
|
expect(out.places.every((p) => p.image_url === null)).toBe(true);
|
|
expect(
|
|
Object.values(out.assignments)
|
|
.flat()
|
|
.every((a) => a.place?.image_url === null),
|
|
).toBe(true);
|
|
expect(out.reservations).toBe(data.reservations);
|
|
expect(data.places[0].image_url).toBe('a.jpg');
|
|
});
|
|
});
|