extract common test setup
This commit is contained in:
@@ -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", () => {
|
it("start in initialized state", () => {
|
||||||
setupTest();
|
setupTest();
|
||||||
|
|
||||||
@@ -254,45 +290,15 @@ describe("Start connection states", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("connection states happy path", async () => {
|
it("connection states happy path", async () => {
|
||||||
setupTest();
|
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
|
|
||||||
const opts: ConnectionOpts = {
|
const connection = setupRemoteConnection();
|
||||||
client: client,
|
|
||||||
focus: livekitFocus,
|
|
||||||
membershipsFocusMap$: fakeMembershipsFocusMap$,
|
|
||||||
scope: testScope,
|
|
||||||
livekitRoomFactory: () => fakeLivekitRoom,
|
|
||||||
}
|
|
||||||
|
|
||||||
const connection = new RemoteConnection(
|
|
||||||
opts,
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const capturedState: FocusConnectionState[] = [];
|
const capturedState: FocusConnectionState[] = [];
|
||||||
connection.focusedConnectionState$.subscribe((value) => {
|
connection.focusedConnectionState$.subscribe((value) => {
|
||||||
capturedState.push(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 connection.start();
|
||||||
await vi.runAllTimersAsync();
|
await vi.runAllTimersAsync();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user