mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
Fix some tests
This commit is contained in:
@@ -16,25 +16,13 @@ import {
|
|||||||
} from "vitest";
|
} from "vitest";
|
||||||
import fetchMock from "fetch-mock";
|
import fetchMock from "fetch-mock";
|
||||||
|
|
||||||
import { mockConfig, ownMemberMock } from "../../../utils/test";
|
import { mockConfig } from "../../../utils/test";
|
||||||
import { getLocalTransport } from "./LocalTransport";
|
import { getLocalTransport } from "./LocalTransport";
|
||||||
import {
|
import { MatrixRTCTransportMissingError } from "../../../utils/errors";
|
||||||
MatrixRTCTransportMissingError,
|
|
||||||
FailToGetOpenIdToken,
|
|
||||||
} from "../../../utils/errors";
|
|
||||||
import * as livekitAuth from "../../../livekit/auth";
|
|
||||||
import { customTransport } from "../../../settings/settings";
|
import { customTransport } from "../../../settings/settings";
|
||||||
import { testJWTToken } from "../../../utils/test-fixtures";
|
|
||||||
import { type MatrixClient } from "matrix-js-sdk";
|
import { type MatrixClient } from "matrix-js-sdk";
|
||||||
|
|
||||||
describe("LocalTransport", () => {
|
describe("LocalTransport", () => {
|
||||||
const sfuConfig: livekitAuth.SFUConfig = {
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
jwt: testJWTToken,
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: "@lk_user:ABCDEF",
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => vi.clearAllMocks());
|
beforeEach(() => vi.clearAllMocks());
|
||||||
|
|
||||||
it("throws if config is missing", async () => {
|
it("throws if config is missing", async () => {
|
||||||
@@ -46,52 +34,20 @@ describe("LocalTransport", () => {
|
|||||||
).rejects.toThrow(new MatrixRTCTransportMissingError("example.org"));
|
).rejects.toThrow(new MatrixRTCTransportMissingError("example.org"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("threes if SFU config fetch fails", async () => {
|
|
||||||
// Provide a valid config so makeTransportInternal resolves a transport
|
|
||||||
mockConfig({
|
|
||||||
livekit: { livekit_service_url: "https://lk.example.org" },
|
|
||||||
});
|
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockRejectedValue(
|
|
||||||
new FailToGetOpenIdToken(new Error("no openid")),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
getLocalTransport({
|
|
||||||
getDomain: () => "example.org",
|
|
||||||
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
|
||||||
}),
|
|
||||||
).rejects.toThrow(new FailToGetOpenIdToken(new Error("no openid")));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns preferred transport", async () => {
|
it("returns preferred transport", async () => {
|
||||||
// Use config so transport discovery succeeds, but delay OpenID JWT fetch
|
// Use config so transport discovery succeeds
|
||||||
mockConfig({
|
mockConfig({
|
||||||
livekit: { livekit_service_url: "https://lk.example.org" },
|
livekit: { livekit_service_url: "https://lk.example.org" },
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockResolvedValue({
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
jwt: "jwt",
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: ownMemberMock.userId + ":" + ownMemberMock.deviceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await getLocalTransport({
|
await getLocalTransport({
|
||||||
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
||||||
getDomain: () => "example.org",
|
getDomain: () => "example.org",
|
||||||
}),
|
}),
|
||||||
).toStrictEqual({
|
).toStrictEqual({
|
||||||
transport: {
|
livekit_service_url: "https://lk.example.org",
|
||||||
livekit_service_url: "https://lk.example.org",
|
type: "livekit",
|
||||||
type: "livekit",
|
|
||||||
},
|
|
||||||
sfuConfig: {
|
|
||||||
jwt: "jwt",
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: "@alice:example.org:DEVICE",
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -116,19 +72,10 @@ describe("LocalTransport", () => {
|
|||||||
mockConfig({
|
mockConfig({
|
||||||
livekit: { livekit_service_url: "https://lk.example.org" },
|
livekit: { livekit_service_url: "https://lk.example.org" },
|
||||||
});
|
});
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockResolvedValue(sfuConfig);
|
|
||||||
|
|
||||||
expect(await getLocalTransport(client)).toStrictEqual({
|
expect(await getLocalTransport(client)).toStrictEqual({
|
||||||
transport: {
|
livekit_service_url: "https://lk.example.org",
|
||||||
livekit_service_url: "https://lk.example.org",
|
type: "livekit",
|
||||||
type: "livekit",
|
|
||||||
},
|
|
||||||
sfuConfig: {
|
|
||||||
jwt: "e30=.eyJzdWIiOiJAbWU6ZXhhbXBsZS5vcmc6QUJDREVGIiwidmlkZW8iOnsicm9vbSI6IiFleGFtcGxlX3Jvb21faWQifX0=.e30=",
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: "@lk_user:ABCDEF",
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,19 +84,10 @@ describe("LocalTransport", () => {
|
|||||||
type: "livekit",
|
type: "livekit",
|
||||||
livekit_service_url: "https://lk.example.org",
|
livekit_service_url: "https://lk.example.org",
|
||||||
});
|
});
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockResolvedValue(sfuConfig);
|
|
||||||
|
|
||||||
expect(await getLocalTransport(client)).toStrictEqual({
|
expect(await getLocalTransport(client)).toStrictEqual({
|
||||||
transport: {
|
livekit_service_url: "https://lk.example.org",
|
||||||
livekit_service_url: "https://lk.example.org",
|
type: "livekit",
|
||||||
type: "livekit",
|
|
||||||
},
|
|
||||||
sfuConfig: {
|
|
||||||
jwt: "e30=.eyJzdWIiOiJAbWU6ZXhhbXBsZS5vcmc6QUJDREVGIiwidmlkZW8iOnsicm9vbSI6IiFleGFtcGxlX3Jvb21faWQifX0=.e30=",
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: "@lk_user:ABCDEF",
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -157,35 +95,13 @@ describe("LocalTransport", () => {
|
|||||||
client._unstable_getRTCTransports.mockResolvedValue([
|
client._unstable_getRTCTransports.mockResolvedValue([
|
||||||
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
||||||
]);
|
]);
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockResolvedValue(sfuConfig);
|
|
||||||
|
|
||||||
expect(await getLocalTransport(client)).toStrictEqual({
|
expect(await getLocalTransport(client)).toStrictEqual({
|
||||||
transport: {
|
livekit_service_url: "https://lk.example.org",
|
||||||
livekit_service_url: "https://lk.example.org",
|
type: "livekit",
|
||||||
type: "livekit",
|
|
||||||
},
|
|
||||||
sfuConfig: {
|
|
||||||
jwt: "e30=.eyJzdWIiOiJAbWU6ZXhhbXBsZS5vcmc6QUJDREVGIiwidmlkZW8iOnsicm9vbSI6IiFleGFtcGxlX3Jvb21faWQifX0=.e30=",
|
|
||||||
livekitAlias: "Akph4alDMhen",
|
|
||||||
livekitIdentity: "@lk_user:ABCDEF",
|
|
||||||
url: "https://lk.example.org",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails fast if the openID request fails for backend config", async () => {
|
|
||||||
client._unstable_getRTCTransports.mockResolvedValue([
|
|
||||||
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
|
||||||
]);
|
|
||||||
vi.spyOn(livekitAuth, "getSFUConfig").mockRejectedValue(
|
|
||||||
new FailToGetOpenIdToken(new Error("Test driven error")),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(getLocalTransport(client)).rejects.toThrow(
|
|
||||||
expect.any(FailToGetOpenIdToken),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("throws if no options are available", async () => {
|
it("throws if no options are available", async () => {
|
||||||
await expect(
|
await expect(
|
||||||
getLocalTransport({
|
getLocalTransport({
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ describe("widget", () => {
|
|||||||
sendToDevice: sendRecvToDevice,
|
sendToDevice: sendRecvToDevice,
|
||||||
receiveToDevice: sendRecvToDevice,
|
receiveToDevice: sendRecvToDevice,
|
||||||
turnServers: false,
|
turnServers: false,
|
||||||
|
rtcLivekitDelegateDelayedLeave: true,
|
||||||
|
rtcLivekitGetToken: true,
|
||||||
rtcTransports: true,
|
rtcTransports: true,
|
||||||
sendDelayedEvents: true,
|
sendDelayedEvents: true,
|
||||||
updateDelayedEvents: true,
|
updateDelayedEvents: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user