fix(tests): chat thread-settings test is idempotent

The row the test writes survives the backup/restore cycle (plugin
tables aren't in the export), so on the second run the GET returned
1 and the "starts at 0" assertion blew up. Explicitly reset the
flag at the start, then flip, then reset again — each run lands
the DB in the same state it started.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
thandClaude Opus 4.6 committed 2026-04-15 21:37:35 +02:00
1 parent 0022f64c50
commit 64be9257f2
1 file changed
+9 -5
+9 -5
View File
@@ -120,18 +120,22 @@ describe('Chat: API', () => {
it('/api/chat/thread-settings round-trips disposable flag', async () => {
const peer = '__test_disposable_flip__';
const initial = await fetch('api/chat/thread-settings?peer=' + encodeURIComponent(peer))
.then(r => r.json());
expect(initial.disposable).toBe(0);
const set = await fetch('api/chat/thread-settings', {
const setFlag = (v) => fetch('api/chat/thread-settings', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
body: JSON.stringify({ peer, disposable: true }),
body: JSON.stringify({ peer, disposable: v }),
}).then(r => r.json());
// Reset from any leftover state (previous runs leave the row
// behind — restore only rolls cards/buckets, not plugin tables).
const reset = await setFlag(false);
expect(reset.disposable).toBe(0);
const set = await setFlag(true);
expect(set.disposable).toBe(1);
const after = await fetch('api/chat/thread-settings?peer=' + encodeURIComponent(peer))
.then(r => r.json());
expect(after.disposable).toBe(1);
// Leave a clean slate for the next run.
await setFlag(false);
});
});