feat: create route to return title information

Summary:

Test Plan:
This commit is contained in:
2024-05-15 23:03:08 -04:00
parent 695a1bb4cd
commit 68c082493e
18 changed files with 1367 additions and 4 deletions

View File

@@ -0,0 +1,127 @@
import { describe, expect, it } from "bun:test";
import app from "~/index";
import { server } from "~/mocks";
server.listen();
describe('requests the "/title" route', () => {
it("with a valid id & token", async () => {
const response = await app.request("/title?id=10", {
headers: new Headers({ "x-anilist-token": "asd" }),
});
expect(response.json()).resolves.toEqual({
success: true,
result: {
nextAiringEpisode: null,
mediaListEntry: {
status: "CURRENT",
progress: 1,
id: 402665918,
},
countryOfOrigin: "JP",
coverImage: {
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx135643-2kJt86K9Db9P.jpg",
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx135643-2kJt86K9Db9P.jpg",
extraLarge:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx135643-2kJt86K9Db9P.jpg",
},
averageScore: 66,
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/135643-cmQZCR3z9dB5.jpg",
status: "FINISHED",
genres: ["Fantasy", "Thriller"],
episodes: 6,
description:
'Once upon a time, brothers Jacob and Wilhelm collected fairy tales from across the land and made them into a book. They also had a much younger sister, the innocent and curious Charlotte, who they loved very much. One day, while the brothers were telling Charlotte a fairy tale like usual, they saw that she had a somewhat melancholy look on her face. She asked them, "Do you suppose they really lived happily ever after?"\n<br><br>\nThe pages of Grimms\' Fairy Tales, written by Jacob and Wilhelm, are now presented from the unique perspective of Charlotte, who sees the stories quite differently from her brothers.\n<br><br>\n(Source: Netflix Anime)',
title: {
userPreferred: "The Grimm Variations",
english: "The Grimm Variations",
},
idMal: 49210,
id: 135643,
},
});
expect(response.status).toBe(200);
});
it("with a valid id but no token", async () => {
const response = await app.request("/title?id=10");
expect(response.json()).resolves.toEqual({
success: true,
result: {
nextAiringEpisode: null,
mediaListEntry: null,
countryOfOrigin: "JP",
coverImage: {
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx135643-2kJt86K9Db9P.jpg",
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx135643-2kJt86K9Db9P.jpg",
extraLarge:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx135643-2kJt86K9Db9P.jpg",
},
averageScore: 66,
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/135643-cmQZCR3z9dB5.jpg",
status: "FINISHED",
genres: ["Fantasy", "Thriller"],
episodes: 6,
description:
'Once upon a time, brothers Jacob and Wilhelm collected fairy tales from across the land and made them into a book. They also had a much younger sister, the innocent and curious Charlotte, who they loved very much. One day, while the brothers were telling Charlotte a fairy tale like usual, they saw that she had a somewhat melancholy look on her face. She asked them, "Do you suppose they really lived happily ever after?"\n<br><br>\nThe pages of Grimms\' Fairy Tales, written by Jacob and Wilhelm, are now presented from the unique perspective of Charlotte, who sees the stories quite differently from her brothers.\n<br><br>\n(Source: Netflix Anime)',
title: {
userPreferred: "The Grimm Variations",
english: "The Grimm Variations",
},
idMal: 49210,
id: 135643,
},
});
expect(response.status).toBe(200);
});
it("with an unknown title from anilist but valid title from amvstrm", async () => {
const response = await app.request("/title?id=50");
expect(response.json()).resolves.toEqual({
success: true,
result: {
nextAiringEpisode: null,
mediaListEntry: null,
coverImage: {
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx151807-yxY3olrjZH4k.png",
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx151807-yxY3olrjZH4k.png",
},
averageScore: 83,
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/151807-37yfQA3ym8PA.jpg",
status: "FINISHED",
genres: ["Action", "Adventure", "Fantasy"],
episodes: 12,
description:
"They say whatever doesnt kill you makes you stronger, but thats not the case for the worlds weakest hunter Sung Jinwoo. After being brutally slaughtered by monsters in a high-ranking dungeon, Jinwoo came back with the System, a program only he could see, thats leveling him up in every way. Now, hes inspired to discover the secrets behind his powers and the dungeon that spawned them.<br>\n<br>\n(Source: Crunchyroll) <br><br>",
title: {
userPreferred: "Ore dake Level Up na Ken",
english: "Solo Leveling",
},
idMal: 52299,
id: 151807,
countryOfOrigin: "JP",
},
});
expect(response.status).toBe(200);
});
it("with an unknown title from all sources", async () => {
const response = await app.request("/title?id=-1");
expect(response.json()).resolves.toEqual({ success: false });
expect(response.status).toBe(404);
});
});