fix: prevent premature queued message auto-send

Only auto-send queued messages after an active session becomes idle
Avoid treating missing initial status as safe to send
Add coverage for queue auto-send status transitions
This commit is contained in:
Bohdan Triapitsyn
2026-05-27 23:36:43 +03:00
parent 5331c4d962
commit 461e2f482c
2 changed files with 26 additions and 6 deletions
@@ -27,7 +27,23 @@ mock.module('@/sync/session-ui-store', () => ({
},
}));
import { buildQueuedAutoSendPayload, sendQueuedAutoSendPayload } from './useQueuedMessageAutoSend';
import {
buildQueuedAutoSendPayload,
sendQueuedAutoSendPayload,
shouldDispatchQueuedAutoSend,
} from './useQueuedMessageAutoSend';
describe('shouldDispatchQueuedAutoSend', () => {
test('dispatches only after an active session becomes idle', () => {
expect(shouldDispatchQueuedAutoSend('busy', 'idle')).toBe(true);
expect(shouldDispatchQueuedAutoSend('retry', 'idle')).toBe(true);
});
test('does not dispatch when idle is only first seen or status is missing', () => {
expect(shouldDispatchQueuedAutoSend(undefined, 'idle')).toBe(false);
expect(shouldDispatchQueuedAutoSend('idle', 'idle')).toBe(false);
});
});
describe('buildQueuedAutoSendPayload', () => {
beforeEach(() => {