import { IVideoSource } from "../resources/videoSource/index"; import VideoSourceService from "../resources/videoSource/service"; describe("VideoSourceService", () => { it("should fetch video sources given video id", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ "data": [ { "type": "source", "id": "192744", "attributes": { "modify_date": "2018-07-23T05:19:33.778341Z", "create_date": "2018-07-23T05:19:33.778379Z", "container": "MP4", "codec": "H264", "src": null, "stream_name": "mp4:5104226627001/5104226627001_5630805396001_5615400608001.mp4?__nn__=1497926354001&slist=5104226627001/&auth=daEdSaxcuc8cvd7b_dsc6cVc4bSa6aCatbx-bBvvla-hca-olACrrry_BJyp_IEDA_FsC&aifp=bcosuds", "app_name": "rtmp://cp150446.edgefcs.net/ondemand", "width": 960, "height": 540, "encoding_rate": 1827000, "size": 26371304, "source_type": null }, "relationships": { "video": { "data": { "type": "video", "id": "520" }, "links": { "related": "/videos/520" } } }, "links": { "self": "/videos/520/sources/192744" } }, { "type": "source", "id": "192743", "attributes": { "modify_date": "2018-07-23T05:19:33.763418Z", "create_date": "2018-07-23T05:19:33.763459Z", "container": "MP4", "codec": "H264", "src": null, "stream_name": "mp4:5104226627001/5104226627001_5630804281001_5615400608001.mp4?__nn__=1497926354001&slist=5104226627001/&auth=daEdSaxcuc8cvd7b_dsc6cVc4bSa6aCatbx-bBvvla-hca-olACrrry_BJyp_IEDA_FsC&aifp=bcosuds", "app_name": "rtmp://cp150446.edgefcs.net/ondemand", "width": 480, "height": 270, "encoding_rate": 513000, "size": 7436881, "source_type": null }, "relationships": { "video": { "data": { "type": "video", "id": "520" }, "links": { "related": "/videos/520" } } }, "links": { "self": "/videos/520/sources/192743" } } ] })))); const service = new VideoSourceService("access123"); service.http = { fetch: fetchMock, }; service.findByVideoId("520", {}) .then((videoSources: IVideoSource[]) => { expect(videoSources).toHaveLength(2); expect(videoSources[0].id).toBe("192744"); expect(videoSources[1].id).toBe("192743"); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/videos/520/sources/", {"headers": {"Authorization": "Bearer access123"}}); }); it("should fetch video source given video and source ids", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ "data": { "type": "source", "id": "192744", "attributes": { "modify_date": "2018-07-23T05:19:33.778341Z", "create_date": "2018-07-23T05:19:33.778379Z", "container": "MP4", "codec": "H264", "src": null, "stream_name": "mp4:5104226627001/5104226627001_5630805396001_5615400608001.mp4?__nn__=1497926354001&slist=5104226627001/&auth=daEdSaxcuc8cvd7b_dsc6cVc4bSa6aCatbx-bBvvla-hca-olACrrry_BJyp_IEDA_FsC&aifp=bcosuds", "app_name": "rtmp://cp150446.edgefcs.net/ondemand", "width": 960, "height": 540, "encoding_rate": 1827000, "size": 26371304, "source_type": null }, "relationships": { "video": { "data": { "type": "video", "id": "520" }, "links": { "related": "/videos/520" } } }, "links": { "self": "/videos/520/sources/192744" } } })))); const service = new VideoSourceService("access123"); service.http = { fetch: fetchMock, }; service.findBySourceId("520", "192744", {}) .then((videoSource: IVideoSource) => { expect(videoSource.id).toBe("192744"); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/videos/520/sources/192744/", {"headers": {"Authorization": "Bearer access123"}}); }); });