test(backend): expand helper and media coverage

This commit is contained in:
2026-04-14 15:30:00 +01:00
parent 928d49250e
commit 5f3daf7922
5 changed files with 238 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
import { describe, expect, test } from 'bun:test';
import { SfuSessionRegistry } from '../media/sfu/registry';
const buildSession = (streamSessionId: string) => ({
streamSessionId,
ownerUserId: 'user-1',
cameraDeviceId: 'camera-1',
requesterDeviceId: 'client-1',
state: 'starting' as const,
createdAt: '2026-04-16T12:00:00.000Z',
});
describe('SFU session registry', () => {
test('stores and retrieves a session descriptor without internal metadata', () => {
const registry = new SfuSessionRegistry();
registry.set(buildSession('stream-1'));
expect(registry.get('stream-1')).toEqual(buildSession('stream-1'));
});
test('returns null when updating a missing session state', () => {
const registry = new SfuSessionRegistry();
expect(registry.updateState('missing-stream', 'live')).toBeNull();
});
test('updates state and lists all registered sessions', () => {
const registry = new SfuSessionRegistry();
registry.set(buildSession('stream-1'));
registry.set({ ...buildSession('stream-2'), cameraDeviceId: 'camera-2' });
expect(registry.updateState('stream-1', 'live')).toEqual({
...buildSession('stream-1'),
state: 'live',
});
expect(registry.list()).toEqual([
{
...buildSession('stream-1'),
state: 'live',
},
{
...buildSession('stream-2'),
cameraDeviceId: 'camera-2',
},
]);
});
});