Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): add probeVideoViaMediaServer unit tests

Richie McIlroyb1122bef6a80
diff --git a/apps/web/__tests__/unit/media-client.test.ts b/apps/web/__tests__/unit/media-client.test.ts
index 1f4663035..400582e9b 100644
--- a/apps/web/__tests__/unit/media-client.test.ts
+++ b/apps/web/__tests__/unit/media-client.test.ts
@@ -4,6 +4,7 @@ import {
extractAudioViaMediaServer,
fetchConvertedVideoViaMediaServer,
isMediaServerConfigured,
+ probeVideoViaMediaServer,
} from "@/lib/media-client";
vi.mock("@cap/env", () => ({
@@ -224,6 +225,56 @@ describe("media-client", () => {
});
});
+ describe("probeVideoViaMediaServer", () => {
+ beforeEach(async () => {
+ const { serverEnv } = await import("@cap/env");
+ vi.mocked(serverEnv).mockReturnValue(
+ mediaServerEnv as ReturnType<typeof serverEnv>,
+ );
+ });
+
+ it("returns authoritative media metadata", async () => {
+ const metadata = {
+ duration: 42,
+ width: 1920,
+ height: 1080,
+ fps: 30,
+ videoCodec: "h264",
+ audioCodec: "aac",
+ audioChannels: 2,
+ sampleRate: 48_000,
+ bitrate: 1_000_000,
+ fileSize: 5_000_000,
+ };
+ mockFetch.mockResolvedValueOnce({
+ ok: true,
+ json: async () => ({ metadata }),
+ });
+
+ await expect(
+ probeVideoViaMediaServer("https://example.com/video.mp4"),
+ ).resolves.toEqual(metadata);
+ });
+
+ it("can disable request retries for synchronous entitlement checks", async () => {
+ mockFetch.mockResolvedValue({
+ ok: false,
+ status: 503,
+ json: async () => ({
+ error: "Server is busy",
+ code: "SERVER_BUSY",
+ }),
+ });
+
+ await expect(
+ probeVideoViaMediaServer("https://example.com/video.mp4", {
+ maxRetries: 0,
+ }),
+ ).rejects.toThrow("Server is busy");
+ expect(mockFetch).toHaveBeenCalledTimes(1);
+ });
+ });
+
describe("fetchConvertedVideoViaMediaServer", () => {
beforeEach(async () => {
const { serverEnv } = await import("@cap/env");