Files
aniplay-api/src/services/episodes/getEpisodeUrl/index.spec.ts

72 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { fetchEpisodeUrl } from "./index";
describe("fetchEpisodeUrl", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("with sources from Aniwatch", async () => {
(global.fetch as any).mockResolvedValue({
ok: true,
json: async () => ({
status: 200,
data: {
tracks: [],
intro: { start: 258, end: 347 },
outro: { start: 1335, end: 1424 },
sources: [
{
url: "https://www032.vipanicdn.net/streamhls/aa804a2400535d84dd59454b28d329fb/ep.1.1712504065.m3u8",
type: "hls",
},
],
anilistID: 153406,
malID: 52635,
},
}),
});
const result = await fetchEpisodeUrl({
id: "4",
aniListId: 153406,
episodeNumber: 1,
});
expect(result).toEqual({
success: true,
result: {
source:
"https://www032.vipanicdn.net/streamhls/aa804a2400535d84dd59454b28d329fb/ep.1.1712504065.m3u8",
subtitles: [],
audio: [],
intro: [258, 347],
outro: [1335, 1424],
headers: undefined,
},
});
});
it("with no URL from Aniwatch source", async () => {
(global.fetch as any).mockResolvedValue({
ok: true,
json: async () => ({
status: 200,
data: {
sources: [],
sub: [],
},
}),
});
const result = await fetchEpisodeUrl({
id: "4",
aniListId: 153406,
episodeNumber: 1,
});
expect(result).toEqual({ success: false });
});
});