@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22import {
33 checkHasAudioTrackViaMediaServer ,
44 extractAudioViaMediaServer ,
5+ fetchConvertedVideoViaMediaServer ,
56 isMediaServerConfigured ,
67} from "@/lib/media-client" ;
78
@@ -189,4 +190,50 @@ describe("media-client", () => {
189190 ) . rejects . toThrow ( "FFmpeg process exited with code 1" ) ;
190191 } ) ;
191192 } ) ;
193+
194+ describe ( "fetchConvertedVideoViaMediaServer" , ( ) => {
195+ beforeEach ( async ( ) => {
196+ const { serverEnv } = await import ( "@cap/env" ) ;
197+ vi . mocked ( serverEnv ) . mockReturnValue ( {
198+ MEDIA_SERVER_URL : "http://localhost:3456" ,
199+ } as ReturnType < typeof serverEnv > ) ;
200+ } ) ;
201+
202+ it ( "throws error when MEDIA_SERVER_URL is not configured" , async ( ) => {
203+ const { serverEnv } = await import ( "@cap/env" ) ;
204+ vi . mocked ( serverEnv ) . mockReturnValue ( {
205+ MEDIA_SERVER_URL : undefined ,
206+ } as unknown as ReturnType < typeof serverEnv > ) ;
207+
208+ await expect (
209+ fetchConvertedVideoViaMediaServer ( "https://example.com/video.m3u8" ) ,
210+ ) . rejects . toThrow ( "MEDIA_SERVER_URL is not configured" ) ;
211+ } ) ;
212+
213+ it ( "posts conversion request to the media server" , async ( ) => {
214+ const mockResponse = {
215+ ok : true ,
216+ status : 200 ,
217+ } as Response ;
218+ mockFetch . mockResolvedValueOnce ( mockResponse ) ;
219+
220+ const result = await fetchConvertedVideoViaMediaServer (
221+ "https://example.com/video.m3u8" ,
222+ ".m3u8" ,
223+ ) ;
224+
225+ expect ( result ) . toBe ( mockResponse ) ;
226+ expect ( mockFetch ) . toHaveBeenCalledWith (
227+ "http://localhost:3456/video/convert" ,
228+ {
229+ method : "POST" ,
230+ headers : { "Content-Type" : "application/json" } ,
231+ body : JSON . stringify ( {
232+ videoUrl : "https://example.com/video.m3u8" ,
233+ inputExtension : ".m3u8" ,
234+ } ) ,
235+ } ,
236+ ) ;
237+ } ) ;
238+ } ) ;
192239} ) ;
0 commit comments