Files
cinny/src/app/utils/callRejoin.test.ts
T
Lotus CIandClaude Opus 5.5 0a2f18e3d5
CI / Build & Quality Checks (pull_request) Successful in 3m16s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 19s
CI / Playwright smoke (e2e) (pull_request) Successful in 16m35s
fix(calls): DM-aware rejoin toast, and no rejoining a DM call that ended (#302)
After a reload during a DM call the toast said "You were in the call in
Bob Builder"; it now says "You were in a call with Bob Builder". DM
calls are never auto-rejoined (it could ring the other person), and if
they have left by the time you tap, the toast says "Call ended" instead
of starting a new, ringing call.

Fixes #302

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-17 20:20:12 -04:00

81 lines
2.6 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import {
CALL_REJOIN_MAX_AGE_MS,
decideRejoin,
othersInCall,
rejoinToastBody,
RejoinContext,
} from './callRejoin';
const base: RejoinContext = {
record: {
roomId: '!r',
deviceId: 'DEV',
joinedAt: 900_000,
lastSeen: 1_000_000,
microphone: true,
video: false,
},
mode: 'ask',
now: 1_060_000,
myDeviceId: 'DEV',
roomJoined: true,
ownMemberDevices: [],
memberCount: 2,
};
describe('decideRejoin', () => {
it('asks by default when the call is still going', () => {
assert.deepEqual(decideRejoin(base), { action: 'ask', roomId: '!r' });
assert.deepEqual(decideRejoin({ ...base, mode: 'auto' }), { action: 'auto', roomId: '!r' });
});
it('does nothing when off, stale, another device, or no record', () => {
assert.deepEqual(decideRejoin({ ...base, mode: 'off' }), { action: 'none' });
assert.deepEqual(decideRejoin({ ...base, record: undefined }), { action: 'none' });
assert.deepEqual(decideRejoin({ ...base, now: 1_000_000 + CALL_REJOIN_MAX_AGE_MS + 1 }), {
action: 'none',
});
assert.deepEqual(decideRejoin({ ...base, myDeviceId: 'OTHER' }), { action: 'none' });
assert.deepEqual(decideRejoin({ ...base, roomJoined: false }), { action: 'none' });
});
it('skips when we already rejoined from another device', () => {
assert.deepEqual(decideRejoin({ ...base, ownMemberDevices: ['PHONE'], memberCount: 2 }), {
action: 'none',
});
});
it('skips when only our own stale membership is left', () => {
assert.deepEqual(decideRejoin({ ...base, ownMemberDevices: ['DEV'], memberCount: 1 }), {
action: 'none',
});
assert.deepEqual(decideRejoin({ ...base, ownMemberDevices: [], memberCount: 0 }), {
action: 'none',
});
assert.deepEqual(decideRejoin({ ...base, ownMemberDevices: ['DEV'], memberCount: 2 }), {
action: 'ask',
roomId: '!r',
});
});
});
it('decideRejoin: DM calls are never auto-rejoined, only offered (#302)', () => {
assert.deepEqual(decideRejoin({ ...base, mode: 'auto', dm: true }), {
action: 'ask',
roomId: '!r',
});
assert.deepEqual(decideRejoin({ ...base, mode: 'auto' }), { action: 'auto', roomId: '!r' });
});
it('rejoinToastBody and othersInCall (#302)', () => {
assert.equal(
rejoinToastBody('Bob Builder', true),
'You were in a call with Bob Builder before the restart. Tap to rejoin.',
);
assert.match(rejoinToastBody('Voice Lounge', false), /in the call in Voice Lounge/);
assert.equal(othersInCall(['@me:x'], '@me:x'), false);
assert.equal(othersInCall(['@me:x', '@bob:x'], '@me:x'), true);
});