Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): cover fetchConvertedVideoViaMediaServer

Richie McIlroy320985d9b01b
diff --git a/apps/web/__tests__/unit/media-client.test.ts b/apps/web/__tests__/unit/media-client.test.ts
index b99fb3467..3dde2824d 100644
--- a/apps/web/__tests__/unit/media-client.test.ts
+++ b/apps/web/__tests__/unit/media-client.test.ts
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import {
checkHasAudioTrackViaMediaServer,
extractAudioViaMediaServer,
+ fetchConvertedVideoViaMediaServer,
isMediaServerConfigured,
} from "@/lib/media-client";
@@ -189,4 +190,50 @@ describe("media-client", () => {
).rejects.toThrow("FFmpeg process exited with code 1");
});
});
+
+ describe("fetchConvertedVideoViaMediaServer", () => {
+ beforeEach(async () => {
+ const { serverEnv } = await import("@cap/env");
+ vi.mocked(serverEnv).mockReturnValue({
+ MEDIA_SERVER_URL: "http://localhost:3456",
+ } as ReturnType<typeof serverEnv>);
+ });
+
+ it("throws error when MEDIA_SERVER_URL is not configured", async () => {
+ const { serverEnv } = await import("@cap/env");
+ vi.mocked(serverEnv).mockReturnValue({
+ MEDIA_SERVER_URL: undefined,
+ } as unknown as ReturnType<typeof serverEnv>);
+
+ await expect(
+ fetchConvertedVideoViaMediaServer("https://example.com/video.m3u8"),
+ ).rejects.toThrow("MEDIA_SERVER_URL is not configured");
+ });
+
+ it("posts conversion request to the media server", async () => {
+ const mockResponse = {
+ ok: true,
+ status: 200,
+ } as Response;
+ mockFetch.mockResolvedValueOnce(mockResponse);
+
+ const result = await fetchConvertedVideoViaMediaServer(
+ "https://example.com/video.m3u8",
+ ".m3u8",
+ );
+
+ expect(result).toBe(mockResponse);
+ expect(mockFetch).toHaveBeenCalledWith(
+ "http://localhost:3456/video/convert",
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ videoUrl: "https://example.com/video.m3u8",
+ inputExtension: ".m3u8",
+ }),
+ },
+ );
+ });
+ });
});