From 64be9257f29fff5d48ac457a186f1f8809f09681 Mon Sep 17 00:00:00 2001
From: th
Date: Wed, 15 Apr 2026 21:37:35 +0200
Subject: [PATCH] fix(tests): chat thread-settings test is idempotent
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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)
---
public/plugins/tests/chat.test.js | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/public/plugins/tests/chat.test.js b/public/plugins/tests/chat.test.js
index 7e9498a..8504c0a 100644
--- a/public/plugins/tests/chat.test.js
+++ b/public/plugins/tests/chat.test.js
@@ -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);
});
});
|