From cc4e24bc8af2a1ed3eed17d4e4e2e820d06cdf19 Mon Sep 17 00:00:00 2001 From: BountyGrid Date: Fri, 28 Aug 2026 15:17:08 -0700 Subject: [PATCH] test(chrome-extension): add unit test coverage for toSessionDescriptionInit --- .../src/shared/webrtc.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/chrome-extension/src/shared/webrtc.test.ts b/apps/chrome-extension/src/shared/webrtc.test.ts index 8bbcc249ce..1461d556ee 100644 --- a/apps/chrome-extension/src/shared/webrtc.test.ts +++ b/apps/chrome-extension/src/shared/webrtc.test.ts @@ -50,3 +50,26 @@ describe("waitForIceGatheringComplete", () => { ); }); }); + +describe("toSessionDescriptionInit", () => { + it("formats valid RTCSessionDescription to RTCSessionDescriptionInit", async () => { + const { toSessionDescriptionInit } = await import("./webrtc"); + const desc = { + type: "offer" as RTCSdpType, + sdp: "v=0\r\no=- 123456 2 IN IP4 127.0.0.1\r\n", + toJSON: () => ({}), + }; + expect(toSessionDescriptionInit(desc as RTCSessionDescription)).toEqual({ + type: "offer", + sdp: "v=0\r\no=- 123456 2 IN IP4 127.0.0.1\r\n", + }); + }); + + it("throws error when session description is null or undefined", async () => { + const { toSessionDescriptionInit } = await import("./webrtc"); + expect(() => toSessionDescriptionInit(null)).toThrow( + "Missing session description", + ); + }); +}); +