Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stop an older list read undoing a session start
Yudhi Armyndharis855872542d5f
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex a19733eeb..7d0025187 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -1364,6 +1364,45 @@ test('a list read in flight does not undo a create, a stop or a delete', async (}});+test('a list read in flight does not undo a start', async () => {+ const { screen, fireEvent, within, waitFor, act } = rtl;+ resetFetchCalls();+ window.sessionStorage.setItem('openwa_api_key', 'test-key');+ startResult = { answer: { status: 'initializing', engineLoaded: true } };+ SESSIONS.push({ ...SESSION_QR, id: 'sess-start-race', name: 'start-race', status: 'created', engineLoaded: false });+ const releases: (() => void)[] = [];+ const gateNextRead = () => {+ listGate = new Promise<void>(resolve => releases.push(resolve));+ };+ try {+ renderSessions();+ const card = (await screen.findByText('start-race')).closest('.session-card') as HTMLElement;+ const reads = () => fetchCalls.filter(c => c.method === 'GET' && c.path === '/api/sessions').length;++ // A push's read snapshots the row before the start and answers late.+ gateNextRead();+ const before = reads();+ pushSessionStatus(SESSION_TIMELOCKED.id, 'action_required');+ await waitFor(() => assert.equal(reads(), before + 1));++ // The start's own re-read is held too, so the older read answers first.+ gateNextRead();+ fireEvent.click(within(card).getByRole('button', { name: 'Start' }));+ await waitFor(() => assert.equal(reads(), before + 2));+ assert.ok(!within(card).queryByRole('button', { name: 'Start' }), 'the start answer was not rendered');++ releases[0]();+ await act(() => new Promise<void>(resolve => setTimeout(resolve, 20)));+ assert.ok(+ !within(card).queryByRole('button', { name: 'Start' }),+ 'a read older than the start put the session back to not started',+ );+ } finally {+ releases.forEach(release => release());+ SESSIONS.pop();+ }+});+// A push for another session, handled before React renders a create or a delete, must patch the list// that write produced rather than the one on screen before it.test('a status push landing right after a create or a delete keeps what it wrote', async () => {diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex 028d6d4d5..826399493 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -389,6 +389,7 @@ export function Sessions() {// from before the start, which now includes `engineLoaded` and would leave the card offering// Start for a session that just acquired an engine.const started = await sessionApi.start(id);+ rowWrites.current += 1;updateSessions(current => replaceSession(current, started));// A 200 does not promise the engine is still there when the list is read back: a concurrent stop// retires the start, and an engine can fail right after answering. Skip the modal when the re-read