refactor: move fetchEpisodes in to subfolder
This commit is contained in:
221
src/controllers/episodes/getByAniListId/index.spec.ts
Normal file
221
src/controllers/episodes/getByAniListId/index.spec.ts
Normal file
@@ -0,0 +1,221 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
|
||||
import app from "~/index";
|
||||
import { server } from "~/mocks";
|
||||
import { mockConsumet } from "~/mocks/consumet";
|
||||
|
||||
server.listen();
|
||||
mockConsumet();
|
||||
|
||||
describe('requests the "/episodes" route', () => {
|
||||
it("with list of episodes from Anify", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/1",
|
||||
{},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({
|
||||
success: true,
|
||||
result: {
|
||||
providerId: "zoro",
|
||||
episodes: [
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=103233",
|
||||
number: 1,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Forgetter I",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=103632",
|
||||
number: 2,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Forgetter II",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=104244",
|
||||
number: 3,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Forgetter III",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=104620",
|
||||
number: 4,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Forgetter IV",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=104844",
|
||||
number: 5,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "File: Glint",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=105761",
|
||||
number: 6,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "File: Dreamspeaker Thea",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=106135",
|
||||
number: 7,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "File: Forgetter Annette",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=106518",
|
||||
number: 8,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Dreamspeaker I",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=106606",
|
||||
number: 9,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Dreamspeaker II",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=106981",
|
||||
number: 10,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Dreamspeaker III",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=107176",
|
||||
number: 11,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "Mission: Dreamspeaker IV",
|
||||
updatedAt: 0,
|
||||
},
|
||||
{
|
||||
id: "/watch/spy-classroom-season-2-18468?ep=107247",
|
||||
number: 12,
|
||||
description: null,
|
||||
img: null,
|
||||
rating: null,
|
||||
title: "File: Flower Garden Lily",
|
||||
updatedAt: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("Anify ID filtered out, returns no episode list from Anify", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/158927",
|
||||
{},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("Anify is disabled, returns no episode list from Anify", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/2",
|
||||
{},
|
||||
{
|
||||
ENABLE_ANIFY: "false",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("with list of episodes from Consumet", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/3",
|
||||
{},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({
|
||||
success: true,
|
||||
result: {
|
||||
providerId: "consumet",
|
||||
episodes: [
|
||||
{
|
||||
id: "consumet-1",
|
||||
number: 1,
|
||||
title: "Consumet 1",
|
||||
updatedAt: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("with list of episodes from Amvstrm", async () => {
|
||||
const response = await app.request(
|
||||
"/episodes/4",
|
||||
{},
|
||||
{
|
||||
ENABLE_ANIFY: "true",
|
||||
},
|
||||
);
|
||||
|
||||
expect(response.json()).resolves.toEqual({
|
||||
success: true,
|
||||
result: {
|
||||
providerId: "amvstrm",
|
||||
episodes: [
|
||||
{
|
||||
id: "amvstrm-1",
|
||||
number: 1,
|
||||
title: "EP 1",
|
||||
updatedAt: 0,
|
||||
img: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("with no episodes from all sources", async () => {
|
||||
const response = await app.request("/episodes/-1");
|
||||
|
||||
expect(response.json()).resolves.toEqual({ success: false });
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user