From 22900161d62d7b854dbf7f1314ea790b6431738a Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 1 Oct 2025 14:47:45 +0200 Subject: [PATCH] extract common test setup --- src/state/Connection.test.ts | 68 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/state/Connection.test.ts b/src/state/Connection.test.ts index 59c60c2e..9fe415c1 100644 --- a/src/state/Connection.test.ts +++ b/src/state/Connection.test.ts @@ -65,6 +65,42 @@ describe("Start connection states", () => { } + async function setupRemoteConnection(): RemoteConnection { + + setupTest() + + const opts: ConnectionOpts = { + client: client, + focus: livekitFocus, + membershipsFocusMap$: fakeMembershipsFocusMap$, + scope: testScope, + livekitRoomFactory: () => fakeLivekitRoom, + } + + fetchMock.post(`${livekitFocus.livekit_service_url}/sfu/get`, + () => { + return { + status: 200, + body: + { + "url": "wss://matrix-rtc.m.localhost/livekit/sfu", + "jwt": "ATOKEN", + }, + } + } + ); + + fakeLivekitRoom + .connect + .mockResolvedValue(undefined); + + const connection = new RemoteConnection( + opts, + undefined, + ); + return connection; + } + it("start in initialized state", () => { setupTest(); @@ -254,45 +290,15 @@ describe("Start connection states", () => { }); it("connection states happy path", async () => { - setupTest(); vi.useFakeTimers(); - const opts: ConnectionOpts = { - client: client, - focus: livekitFocus, - membershipsFocusMap$: fakeMembershipsFocusMap$, - scope: testScope, - livekitRoomFactory: () => fakeLivekitRoom, - } - - const connection = new RemoteConnection( - opts, - undefined, - ); + const connection = setupRemoteConnection(); const capturedState: FocusConnectionState[] = []; connection.focusedConnectionState$.subscribe((value) => { capturedState.push(value); }); - // mock the /sfu/get call - fetchMock.post(`${livekitFocus.livekit_service_url}/sfu/get`, - () => { - return { - status: 200, - body: - { - "url": "wss://matrix-rtc.m.localhost/livekit/sfu", - "jwt": "ATOKEN", - }, - } - } - ); - - fakeLivekitRoom - .connect - .mockResolvedValue(undefined); - await connection.start(); await vi.runAllTimersAsync();