Derive client domain types from the shared schema contracts

Add entity/response Zod schemas to @trek/shared (place, trip, assignment, day, budget, packing, reservation), each matched against the producing server service, and re-export them from client types.ts instead of the hand-written duplicates that had drifted (name/title, amount/total_price, owner_id/user_id, cover_url/cover_image, ...). Updates the call sites and test fixtures the corrected types surfaced; type-only, no runtime behaviour change.
This commit is contained in:
Maurice
2026-05-31 15:42:39 +02:00
parent 239a68bb48
commit 3977a5ecba
52 changed files with 732 additions and 435 deletions
@@ -42,20 +42,20 @@ describe('reservationsSlice', () => {
describe('addReservation', () => {
it('FE-RESERV-002: addReservation prepends to reservations array', async () => {
const existing = buildReservation({ trip_id: 1, name: 'Existing' });
const existing = buildReservation({ trip_id: 1, title: 'Existing' });
seedStore(useTripStore, { reservations: [existing] });
const result = await useTripStore.getState().addReservation(1, {
name: 'New Hotel',
title: 'New Hotel',
type: 'hotel',
status: 'pending',
});
expect(result.name).toBe('New Hotel');
expect(result.title).toBe('New Hotel');
const reservations = useTripStore.getState().reservations;
expect(reservations).toHaveLength(2);
// addReservation prepends
expect(reservations[0].name).toBe('New Hotel');
expect(reservations[0].title).toBe('New Hotel');
});
it('FE-RESERV-003: addReservation on failure throws', async () => {
@@ -66,14 +66,14 @@ describe('reservationsSlice', () => {
);
await expect(
useTripStore.getState().addReservation(1, { name: 'Fail' })
useTripStore.getState().addReservation(1, { title: 'Fail' })
).rejects.toThrow();
});
});
describe('updateReservation', () => {
it('FE-RESERV-004: updateReservation replaces item in array by id', async () => {
const reservation = buildReservation({ id: 10, trip_id: 1, name: 'Old', status: 'pending' });
const reservation = buildReservation({ id: 10, trip_id: 1, title: 'Old', status: 'pending' });
seedStore(useTripStore, { reservations: [reservation] });
server.use(
@@ -83,10 +83,10 @@ describe('reservationsSlice', () => {
}),
);
const result = await useTripStore.getState().updateReservation(1, 10, { name: 'Updated Hotel' });
const result = await useTripStore.getState().updateReservation(1, 10, { title: 'Updated Hotel' });
expect(result.name).toBe('Updated Hotel');
expect(useTripStore.getState().reservations[0].name).toBe('Updated Hotel');
expect(result.title).toBe('Updated Hotel');
expect(useTripStore.getState().reservations[0].title).toBe('Updated Hotel');
});
});