test: verify request references on database failures

This commit is contained in:
syntaxbullet
2026-09-04 18:38:58 +02:00
parent 19a9aa6862
commit 16d92f171c

View File

@@ -5,7 +5,7 @@ beforeEach(() => { f = fixture(); }); afterEach(() => f.close());
test('failed revision writes roll back the habit atomically and do not expose database errors', async () => { test('failed revision writes roll back the habit atomically and do not expose database errors', async () => {
f.sqlite.exec("CREATE TRIGGER reject_revision BEFORE INSERT ON habit_revisions BEGIN SELECT RAISE(ABORT, 'private database detail'); END"); f.sqlite.exec("CREATE TRIGGER reject_revision BEFORE INSERT ON habit_revisions BEGIN SELECT RAISE(ABORT, 'private database detail'); END");
const response = await f.request('/habits', 'POST', { name: 'Rollback', method: 'manual' }); const response = await f.request('/habits', 'POST', { name: 'Rollback', method: 'manual' });
expect(response.status).toBe(500); expect(await response.json()).toEqual({ error: 'Internal server error' }); expect(response.status).toBe(500); expect(await response.json()).toEqual({ error: 'Internal server error', requestId: response.headers.get('x-request-id') });
expect((await f.json('/habits')).habits).toHaveLength(0); expect((await f.json('/habits')).habits).toHaveLength(0);
}); });
@@ -20,7 +20,7 @@ test('creation saves color atomically and never puts presentation into requireme
f.sqlite.exec("CREATE TRIGGER reject_color BEFORE INSERT ON habit_calendar_settings BEGIN SELECT RAISE(ABORT, 'private color detail'); END"); f.sqlite.exec("CREATE TRIGGER reject_color BEFORE INSERT ON habit_calendar_settings BEGIN SELECT RAISE(ABORT, 'private color detail'); END");
const response = await f.request('/habits', 'POST', { name: 'Rollback color', method: 'manual', color: '#426582' }); const response = await f.request('/habits', 'POST', { name: 'Rollback color', method: 'manual', color: '#426582' });
expect(response.status).toBe(500); expect(response.status).toBe(500);
expect(await response.json()).toEqual({ error: 'Internal server error' }); expect(await response.json()).toEqual({ error: 'Internal server error', requestId: response.headers.get('x-request-id') });
expect((await f.json('/habits')).habits).toHaveLength(3); expect((await f.json('/habits')).habits).toHaveLength(3);
}); });
test('edits save color with requirements atomically, preserving history and other settings', async () => { test('edits save color with requirements atomically, preserving history and other settings', async () => {