test: migrate from bun to pnpm and vitest
This commit is contained in:
@@ -1,47 +1,71 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import app from "~/index";
|
||||
import { server } from "~/mocks";
|
||||
import { fetchEpisodeUrl } from "./index";
|
||||
|
||||
server.listen();
|
||||
describe("fetchEpisodeUrl", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('requests the "/episodes/:id/url" route', () => {
|
||||
it("with sources from Aniwatch", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/4/url",
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
episodeNumber: 1,
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
(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,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
expect(response.json()).resolves.toEqual({
|
||||
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 () => {
|
||||
const response = await app.request("/episodes/-1/url", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
episodeNumber: -1,
|
||||
(global.fetch as any).mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
status: 200,
|
||||
data: {
|
||||
sources: [],
|
||||
sub: [],
|
||||
},
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
const result = await fetchEpisodeUrl({
|
||||
id: "4",
|
||||
aniListId: 153406,
|
||||
episodeNumber: 1,
|
||||
});
|
||||
|
||||
expect(result).toEqual({ success: false });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user