mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
feat(journey): update_journey takes every setting REST does and answers what it replaced
The MCP tool lacked show_trip_tracks and cover_gradient, which PATCH /api/journeys/:id has always taken. Both now read the input through one helper, and the tool goes through a small settings service that writes the same patch in a transaction with the stored values it replaces, answered as previous, so a change can be written back. The subtitle and the cover gradient take null to clear them. The tool's inline zod moves into strict schemas in @trek/shared; the REST route and its body are unchanged.
This commit is contained in:
@@ -454,6 +454,54 @@ describe('journey write tools', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('update_journey answers what the changed settings held before, flags as booleans, and only those', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h, 'Before');
|
||||
const updated = parseToolResult(
|
||||
await h.client.callTool({
|
||||
name: 'update_journey',
|
||||
arguments: { journeyId: journey.id, title: 'After', show_mood: false, status_override: 'live' },
|
||||
}),
|
||||
) as { journey: { title: string; show_mood: number }; previous: Record<string, unknown> };
|
||||
expect(updated.journey).toMatchObject({ title: 'After', show_mood: 0 });
|
||||
expect(updated.previous).toEqual({ title: 'Before', show_mood: true, status_override: null });
|
||||
// Nothing to change answers the journey as it is, with nothing replaced.
|
||||
const same = parseToolResult(
|
||||
await h.client.callTool({ name: 'update_journey', arguments: { journeyId: journey.id } }),
|
||||
) as { previous: Record<string, unknown> };
|
||||
expect(same.previous).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
it('update_journey takes the trip tracks and the cover gradient the REST route takes, and clears a subtitle', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const updated = parseToolResult(
|
||||
await h.client.callTool({
|
||||
name: 'update_journey',
|
||||
arguments: {
|
||||
journeyId: journey.id,
|
||||
show_trip_tracks: true,
|
||||
cover_gradient: 'linear-gradient(to right, #ff0000, #0000ff)',
|
||||
subtitle: null,
|
||||
},
|
||||
}),
|
||||
) as { journey: { show_trip_tracks: number; cover_gradient: string; subtitle: string | null } };
|
||||
expect(updated.journey).toMatchObject({
|
||||
show_trip_tracks: 1,
|
||||
cover_gradient: 'linear-gradient(to right, #ff0000, #0000ff)',
|
||||
subtitle: null,
|
||||
});
|
||||
const refused = await h.client.callTool({
|
||||
name: 'update_journey',
|
||||
arguments: { journeyId: journey.id, show_trip_tracks: 'yes' },
|
||||
});
|
||||
expect(refused.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('delete_journey removes it and refuses a foreign journey', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { journeyId } = await foreignJourney();
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* The one reading of a journey's settings both the REST route and the MCP
|
||||
* tool update through, and what an update replaced, as the undo writes it
|
||||
* back: only the columns the update named, flags as booleans.
|
||||
*/
|
||||
import { journeySettingsPatch, previousSettings } from '../../../src/nest/journey/journey-settings.helpers';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('journeySettingsPatch', () => {
|
||||
it('JSET-001: writes only what the input names, every flag as 0 or 1, null where it clears', () => {
|
||||
expect(journeySettingsPatch({ title: 'Japan', show_mood: false, show_trip_tracks: true, subtitle: null })).toEqual({
|
||||
title: 'Japan',
|
||||
subtitle: null,
|
||||
show_mood: 0,
|
||||
show_trip_tracks: 1,
|
||||
});
|
||||
expect(journeySettingsPatch({})).toEqual({});
|
||||
expect(journeySettingsPatch({ auto_prepare_recordings: 1, cover_gradient: null })).toEqual({
|
||||
auto_prepare_recordings: 1,
|
||||
cover_gradient: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('JSET-002: leaves a status or an override outside its allow-list alone, and takes null back to the dates', () => {
|
||||
expect(journeySettingsPatch({ status: 'bogus', status_override: 'upcoming' })).toEqual({});
|
||||
expect(journeySettingsPatch({ status: 'archived', status_override: null })).toEqual({
|
||||
status: 'archived',
|
||||
status_override: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('previousSettings', () => {
|
||||
const row = { title: 'Japan', subtitle: null, show_mood: 1, show_verdict: 0, status: 'active', cover_gradient: null };
|
||||
|
||||
it('JSET-010: reads the stored values of exactly the written columns, flags as booleans', () => {
|
||||
const patch = journeySettingsPatch({ title: 'Nippon', show_mood: false, show_verdict: true, subtitle: 'Autumn' });
|
||||
expect(previousSettings(row, patch)).toEqual({
|
||||
title: 'Japan',
|
||||
subtitle: null,
|
||||
show_mood: true,
|
||||
show_verdict: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('JSET-011: a column the row does not hold reads as null, and a journey that is gone gives nulls', () => {
|
||||
const patch = journeySettingsPatch({ status_override: 'live', show_weather: true });
|
||||
expect(previousSettings(row, patch)).toEqual({ status_override: null, show_weather: false });
|
||||
expect(previousSettings(undefined, journeySettingsPatch({ title: 'X' }))).toEqual({ title: null });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user