mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
ed18c37903
Every file the release touches was read once more, and what survived an independent check against the code is fixed here, with a test for each. Data and credentials - A document sync connection edited to a new address no longer carries the stored token along: a blank form under another origin is refused, the same rule the probe route already had. Dawarich and AirTrail testConnection send the stored key only to the host it was stored for. - The key rotation script now covers document_connections.secrets and trip_document_links.webhook_secret, which it had skipped. - Turning a booked night into a pause in the road trip popup asks first and says that the booking and its expense go with it. Deleting a place says the same when a night is booked there, on the desktop and on the phone. - A moved version marker over unchanged bytes no longer replaces the TREK file and its attachments; a real revision carries the attachments over. Planner - A drop in the day plan names the row it lands ahead of in the full day, so a hidden hotel stop no longer shifts it one slot early; the store sorts before it splices. Via re-anchoring, the booked-night guard and the sidebar's day membership read the stored day, the index space the server uses. - A hotel stop placed mid-day re-pins the road trip vias of that day, and the booking session receives the new stop order too. The Public API and the iCal feed list a booked hotel once. A plugin can no longer write a stay against another trip's day. Road trip and map - The route overview paces its requests to the public routers and retries a rate limit, and it says which legs it could not route instead of quietly reporting a shorter trip. A click on a via handle no longer drops a second via; handles hide when zooming out. Read-only members cannot edit the driving limits. The phone shows a way back when no day is picked and prints the night drive departure in the chosen clock format. Integrations and search - Google transit keeps conventional trains when the train chip is on. TREK_PLACES_ENABLED=false stops the details and enrichment calls too, and accepts the whole boolean family. A caller-supplied description no longer lands in the instance-wide enrichment cache. Nominatim searches carry a timeout. An OSM place id is checked for shape before it reaches Overpass. - Dawarich puts a stay on the trip whose dates hold it, the Atlas hand-off knows what the Atlas already shows, and a host change with a new key clears the old instance's state. - Document sync: a webhook address pasted by hand works on the token alone, deleting a connection unregisters its subscriptions, Nextcloud under a sub-path connects, Synology answers a name collision before uploading and verifies a move into the bin, Paperless titles are capped at 128 characters, a DNS failure reads as unreachable rather than as a policy verdict, videos from the store are accepted like uploads, and remote_missing has a way out. Conflict buttons only for the owner, a refused choice is reported, a refused credential gets a Reconnect button, disconnecting asks first on the desktop as it does on the phone, and the folder picker no longer spins forever. Release - The server holds the release notice back from a bundle that cannot draw it, so the previous shell served from the service worker cache after an update no longer shows bare keys and no longer lets a click use the notice up. - Import into an existing list gets the same body limit as a new list. Chat images say when the limit is reached and the new controls are translated. The transit backend switch reports a failed save. The Helm chart carries the Amap credentials in its Secret; the shipped templates document the Places API and Amap variables and the Overpass default. The wiki follows.
192 lines
11 KiB
TypeScript
192 lines
11 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { HttpException } from '@nestjs/common';
|
|
import { AccommodationsController } from '../../../src/nest/accommodations/accommodations.controller';
|
|
import type { AccommodationsService } from '../../../src/nest/accommodations/accommodations.service';
|
|
import type { User } from '../../../src/types';
|
|
|
|
const user = { id: 1, role: 'user', email: 'u@example.test' } as User;
|
|
const trip = { user_id: 1 };
|
|
const refs = { place_id: 2, start_day_id: 10, end_day_id: 11 };
|
|
/** A write that left the day plan alone, which is what most of these cases are about. */
|
|
const noMirror = { created: null, removed: [], stamped: null };
|
|
|
|
function makeService(overrides: Partial<AccommodationsService> = {}): AccommodationsService {
|
|
return {
|
|
verifyTripAccess: vi.fn().mockReturnValue(trip),
|
|
canEdit: vi.fn().mockReturnValue(true),
|
|
broadcast: vi.fn(),
|
|
announceMirror: vi.fn(),
|
|
validateRefs: vi.fn().mockReturnValue([]),
|
|
...overrides,
|
|
} as unknown as AccommodationsService;
|
|
}
|
|
|
|
function thrown(fn: () => unknown): { status: number; body: unknown } {
|
|
try { fn(); } catch (err) {
|
|
expect(err).toBeInstanceOf(HttpException);
|
|
const e = err as HttpException;
|
|
return { status: e.getStatus(), body: e.getResponse() };
|
|
}
|
|
throw new Error('expected throw');
|
|
}
|
|
|
|
describe('AccommodationsController (parity with the legacy accommodations sub-router)', () => {
|
|
|
|
it('GET / lists (no permission gate)', () => {
|
|
const svc = makeService({ list: vi.fn().mockReturnValue([{ id: 1 }]) } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).list(user, '5')).toEqual({ accommodations: [{ id: 1 }] });
|
|
});
|
|
|
|
describe('POST /', () => {
|
|
|
|
it('400 when refs are missing', () => {
|
|
expect(thrown(() => new AccommodationsController(makeService()).create(user, '5', { place_id: 2 }))).toEqual({
|
|
status: 400, body: { error: 'place_id, start_day_id, and end_day_id are required' },
|
|
});
|
|
});
|
|
|
|
it('404 with the first validateRefs error message', () => {
|
|
const svc = makeService({ validateRefs: vi.fn().mockReturnValue([{ field: 'place_id', message: 'Place not found' }]) } as Partial<AccommodationsService>);
|
|
expect(thrown(() => new AccommodationsController(svc).create(user, '5', refs))).toEqual({ status: 404, body: { error: 'Place not found' } });
|
|
});
|
|
|
|
it('creates and emits accommodation:created + reservation:created', () => {
|
|
const create = vi.fn().mockReturnValue({ accommodation: { id: 9 }, mirror: noMirror });
|
|
const broadcast = vi.fn();
|
|
const svc = makeService({ create, broadcast } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).create(user, '5', refs, 'sock')).toEqual({ accommodation: { id: 9 }, assignment: null });
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'accommodation:created', { accommodation: { id: 9 } }, 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'reservation:created', {}, 'sock');
|
|
});
|
|
|
|
it('ACC-CTL-001 hands the day stop back in the answer and announces it', () => {
|
|
// The stop reaches the session that booked the night over the socket as well;
|
|
// the answer is what it has left when that socket is down.
|
|
const stop = { id: 77, day_id: 10 };
|
|
const create = vi.fn().mockReturnValue({ accommodation: { id: 9 }, mirror: { created: stop, removed: [], stamped: null } });
|
|
const announceMirror = vi.fn();
|
|
const svc = makeService({ create, announceMirror } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).create(user, '5', refs, 'sock')).toEqual({ accommodation: { id: 9 }, assignment: stop });
|
|
expect(announceMirror).toHaveBeenCalledWith('5', { created: stop, removed: [], stamped: null }, expect.any(Function), 'sock');
|
|
});
|
|
});
|
|
|
|
describe('PUT /:id', () => {
|
|
it('404 when the accommodation is missing', () => {
|
|
const svc = makeService({ get: vi.fn().mockReturnValue(undefined) } as Partial<AccommodationsService>);
|
|
expect(thrown(() => new AccommodationsController(svc).update(user, '5', '9', refs))).toEqual({ status: 404, body: { error: 'Accommodation not found' } });
|
|
});
|
|
|
|
it('updates and broadcasts', () => {
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const update = vi.fn().mockReturnValue({ accommodation: { id: 9, notes: 'x' }, mirror: noMirror });
|
|
const broadcast = vi.fn();
|
|
const svc = makeService({ get, update, broadcast } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).update(user, '5', '9', refs, 'sock')).toEqual({ accommodation: { id: 9, notes: 'x' }, assignment: null, removedAssignments: [] });
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'accommodation:updated', { accommodation: { id: 9, notes: 'x' } }, 'sock');
|
|
});
|
|
|
|
it('ACC-CTL-002 a booking moved to another day reports the stop it took with it', () => {
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const mirror = { created: { id: 78, day_id: 11 }, removed: [{ id: 77, dayId: 10 }], stamped: null };
|
|
const update = vi.fn().mockReturnValue({ accommodation: { id: 9 }, mirror });
|
|
const announceMirror = vi.fn();
|
|
const svc = makeService({ get, update, announceMirror } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).update(user, '5', '9', refs, 'sock'))
|
|
.toEqual({ accommodation: { id: 9 }, assignment: mirror.created, removedAssignments: mirror.removed });
|
|
expect(announceMirror).toHaveBeenCalledWith('5', mirror, expect.any(Function), 'sock');
|
|
});
|
|
|
|
it('ACC-CTL-003 404s a place or day that is not on this trip, before the write', () => {
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const update = vi.fn();
|
|
const validateRefs = vi.fn().mockReturnValue([{ message: 'Place not found' }]);
|
|
const svc = makeService({ get, update, validateRefs } as Partial<AccommodationsService>);
|
|
expect(thrown(() => new AccommodationsController(svc).update(user, '5', '9', refs)))
|
|
.toEqual({ status: 404, body: { error: 'Place not found' } });
|
|
expect(update).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('ACC-CTL-004 the mirror sender is the same broadcast, reaching the sender too', () => {
|
|
// announceMirror decides which events a stay write implies; the controller only
|
|
// hands it the door out. That door must not skip the sender's socket: the day's
|
|
// new order and its re-pinned vias are not in the answer, and a session that
|
|
// takes the stop from the answer alone keeps the stops behind it on their old
|
|
// numbers. The stop itself arriving twice is a duplicate the store drops.
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const mirror = { created: { id: 78, day_id: 11 }, removed: [{ id: 77, dayId: 10 }], stamped: null };
|
|
const update = vi.fn().mockReturnValue({ accommodation: { id: 9 }, mirror });
|
|
const broadcast = vi.fn();
|
|
type Send = (event: string, payload: unknown) => void;
|
|
const announceMirror = vi.fn((_tripId: string, m: typeof mirror, send: Send) => {
|
|
for (const stop of m.removed) send('assignment:deleted', { assignmentId: stop.id, dayId: stop.dayId });
|
|
if (m.created) send('assignment:created', { assignment: m.created });
|
|
send('assignment:reordered', { dayId: 11, orderedIds: [70, 78, 71] });
|
|
send('roadtripVia:changed', { dayId: 11, vias: [] });
|
|
});
|
|
const svc = makeService({ get, update, broadcast, announceMirror } as Partial<AccommodationsService>);
|
|
new AccommodationsController(svc).update(user, '5', '9', refs, 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'assignment:deleted', { assignmentId: 77, dayId: 10 }, undefined);
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'assignment:created', { assignment: mirror.created }, undefined);
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'assignment:reordered', { dayId: 11, orderedIds: [70, 78, 71] }, undefined);
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'roadtripVia:changed', { dayId: 11, vias: [] }, undefined);
|
|
// The booking's own event is still the sender's echo, and still suppressed, and
|
|
// the journey reconcile behind announceMirror still gets the socket id (ACC-CTL-002).
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'accommodation:updated', { accommodation: { id: 9 } }, 'sock');
|
|
});
|
|
});
|
|
|
|
describe('DELETE /:id', () => {
|
|
it('404 when missing', () => {
|
|
const svc = makeService({ get: vi.fn().mockReturnValue(undefined) } as Partial<AccommodationsService>);
|
|
expect(thrown(() => new AccommodationsController(svc).remove(user, '5', '9'))).toEqual({ status: 404, body: { error: 'Accommodation not found' } });
|
|
});
|
|
|
|
it('emits the linked reservation/budget cascade then accommodation:deleted', () => {
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const remove = vi.fn().mockReturnValue({
|
|
linkedReservationId: 4, deletedBudgetItemId: 7,
|
|
linkedReservationIds: [4], deletedBudgetItemIds: [7], mirror: noMirror,
|
|
});
|
|
const broadcast = vi.fn();
|
|
const svc = makeService({ get, remove, broadcast } as Partial<AccommodationsService>);
|
|
expect(new AccommodationsController(svc).remove(user, '5', '9', 'sock')).toEqual({ success: true, removedAssignments: [] });
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'reservation:deleted', { reservationId: 4 }, 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'budget:deleted', { itemId: 7 }, 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'accommodation:deleted', { accommodationId: 9 }, 'sock');
|
|
});
|
|
|
|
it('emits one event per booking when a stay carried more than one (#1869)', () => {
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const remove = vi.fn().mockReturnValue({
|
|
linkedReservationId: 4, deletedBudgetItemId: null,
|
|
linkedReservationIds: [4, 5], deletedBudgetItemIds: [], mirror: noMirror,
|
|
});
|
|
const broadcast = vi.fn();
|
|
const svc = makeService({ get, remove, broadcast } as Partial<AccommodationsService>);
|
|
new AccommodationsController(svc).remove(user, '5', '9', 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'reservation:deleted', { reservationId: 4 }, 'sock');
|
|
expect(broadcast).toHaveBeenCalledWith('5', 'reservation:deleted', { reservationId: 5 }, 'sock');
|
|
});
|
|
|
|
it('ACC-CTL-005 ?keepStop=true is what turns a night back into an ordinary pause', () => {
|
|
// The road trip popup switching the night off: the booking goes, the stop it
|
|
// brought stays where it is in the drive. Nothing else may pass that flag, so
|
|
// only the literal string counts.
|
|
const get = vi.fn().mockReturnValue({ id: 9 });
|
|
const remove = vi.fn().mockReturnValue({
|
|
linkedReservationId: null, deletedBudgetItemId: null,
|
|
linkedReservationIds: [], deletedBudgetItemIds: [], mirror: noMirror,
|
|
});
|
|
const svc = makeService({ get, remove } as Partial<AccommodationsService>);
|
|
const controller = new AccommodationsController(svc);
|
|
|
|
controller.remove(user, '5', '9', 'sock', 'true');
|
|
expect(remove).toHaveBeenLastCalledWith('9', { keepStop: true });
|
|
|
|
controller.remove(user, '5', '9', 'sock');
|
|
expect(remove).toHaveBeenLastCalledWith('9', { keepStop: false });
|
|
});
|
|
});
|
|
});
|