mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
fix(journey): refuse the second of two saves of a recorded day at once unless it asked to replace
This commit is contained in:
@@ -104,6 +104,19 @@ describe('JourneyRecordedDaysRepository', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('JRDAYS-007: a write that keeps only while none is kept leaves the version there first and says so', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
const first = await days.insertDayIfAbsent(day(j.id, user.id));
|
||||
expect(first).toEqual(expect.any(Number));
|
||||
|
||||
expect(await days.insertDayIfAbsent(day(j.id, user.id, { content_hash: 'b'.repeat(64) }))).toBeUndefined();
|
||||
expect(await countRows(t, JourneyRecordedDays, {})).toBe(1);
|
||||
expect(await days.findDay(j.id, '2026-05-14', 'dawarich')).toMatchObject({
|
||||
id: first,
|
||||
content_hash: 'a'.repeat(64),
|
||||
});
|
||||
});
|
||||
|
||||
it('JRDAYS-003: lists the days of one journey earliest first, and only its own', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
const other = await makeJourney(t, user.id);
|
||||
|
||||
@@ -259,6 +259,29 @@ describe('JourneyRecordingsService.save', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('JRNREC-SVC-013: of two editors saving the day at once without Replace, the second is refused, not silently kept', async () => {
|
||||
const f = await fixture();
|
||||
fetchDay.mockResolvedValue(recorded());
|
||||
await svc.save(f.editor.id, f.journey.id, '2026-05-14', await previewed(f.editor.id, f.journey.id));
|
||||
t.realtime.reset();
|
||||
|
||||
fetchDay.mockResolvedValue(recorded({ segments: [WALK, { ...WALK, startedAt: '2026-05-14T15:00:00+02:00' }] }));
|
||||
const body = await previewed(f.owner.id, f.journey.id);
|
||||
// The owner read the day before the editor's write landed.
|
||||
const staleRead = vi.spyOn(kept, 'find').mockResolvedValueOnce(null);
|
||||
|
||||
expect(await refusal(svc.save(f.owner.id, f.journey.id, '2026-05-14', body))).toEqual({
|
||||
status: 409,
|
||||
body: { error: 'The journey already keeps another recording of that day', code: 'recording_exists' },
|
||||
});
|
||||
staleRead.mockRestore();
|
||||
expect(await kept.find(f.journey.id, '2026-05-14')).toMatchObject({
|
||||
importedBy: { id: f.editor.id, username: 'jonas' },
|
||||
stats: { segmentCount: 1 },
|
||||
});
|
||||
expect(t.realtime.broadcastToUserMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('JRNREC-SVC-008: a recording that changed since the preview is not kept, and the kept version stays', async () => {
|
||||
const f = await fixture();
|
||||
fetchDay.mockResolvedValue(recorded());
|
||||
|
||||
Reference in New Issue
Block a user