Files
mangabaka-seeder/test/kakaopage-parse.test.ts
T

44 lines
2.7 KiB
TypeScript

import { expect, test } from "bun:test";
import { extractCovers, parseOverview } from "../src/core/sources/kakaopage/parse";
import { fixtureJson, fixtureText } from "./helpers/fixtures";
const IMG = "https://page-images.kakaoentcdn.com/download/resource?kid=";
test("overview of a comic: title, language, age grade, portrait and landscape", async () => {
const o = parseOverview(await fixtureJson("kakaopage/overview-54845189.json"));
expect(o).toMatchObject({ id: "54845189", title: "악역의 엔딩은 죽음뿐", language: "ko", ageGrade: 0, novel: false });
expect(o.covers.map((c) => [c.role, c.url])).toEqual([
["poster", `${IMG}mW3j5/dJMcaacSrAK/WVoJJAYNlS9rayXUWi6AY0&filename=o1`],
["banner", `${IMG}RmobN/hzCtfKUqaD/6XgE5RjbBGMOn6thodamr0&filename=o1`],
]);
});
test("a novel, and a 19+ edition without a landscape image", async () => {
expect(parseOverview(await fixtureJson("kakaopage/overview-52654302-novel.json"))).toMatchObject({ id: "52654302", novel: true });
const adult = parseOverview(await fixtureJson("kakaopage/overview-63659962-19.json"));
expect(adult).toMatchObject({ id: "63659962", ageGrade: 19 });
expect(adult.covers.map((c) => c.role)).toEqual(["poster"]);
});
test("an answer without content is an error naming the reason", () => {
expect(() => parseOverview({ result: null, message: "상품 정보를 찾을 수 없습니다." })).toThrow(/상품 정보를 찾을 수 없습니다/);
expect(() => parseOverview("nonsense")).toThrow(/KakaoPage/);
});
test("2020 capture (old address): og:image plus the series' own thumbnails", async () => {
const covers = extractCovers(await fixtureText("wayback/kakaopage-54845189-2020.html"), new URL("https://page.kakao.com/home?seriesId=54845189"));
expect(covers.map((c) => [c.role, c.url])).toEqual([
["poster", `${IMG}dNtPVq/hyCvfq21v6/b4EGtZDhGNKvzdBjWXg290&filename=o1`],
["banner", `${IMG}bx4cET/hyATqBNkj9/kUeJCNRNNpYDYRBtpK1Oh1&filename=o1`],
]);
});
test("2022 and 2024 captures: the og:image only (other series on the page are ignored)", async () => {
const at = (y: number) => fixtureText(`wayback/kakaopage-54845189-${y}.html`);
const page = new URL("https://page.kakao.com/content/54845189");
expect(extractCovers(await at(2022), page).map((c) => [c.role, c.url])).toEqual([["other", `${IMG}RmobN/hzCtfKUqaD/6XgE5RjbBGMOn6thodamr0&filename=o1`]]);
const y2024 = extractCovers(await at(2024), page);
expect(y2024.map((c) => [c.role, c.url])).toEqual([["other", `${IMG}dBnFgi/hzXap8fqJ4/Kzjixkeeek6kH1eOyRb490&filename=o1`]]);
expect(y2024[0]!.originalUrl).toBe("https://page-images.kakaoentcdn.com/download/resource?kid=dBnFgi/hzXap8fqJ4/Kzjixkeeek6kH1eOyRb490&filename=o1");
});