Files
mangabaka-seeder/test/links.test.ts
T

27 lines
1.0 KiB
TypeScript

import { expect, test } from "bun:test";
import { LinkError, parseLink, parseMangaBakaSeriesId } from "../src/core/links";
test.each([
["9999", 9999],
[" 9999 ", 9999],
["https://mangabaka.org/9999", 9999],
["https://mangabaka.org/manhwa/9999/Tower-of-God", 9999],
["mangabaka.org/manhwa/9999/Tower-of-God", 9999],
["https://www.mangabaka.org/manhwa/9999", 9999],
["https://mangabaka.org/data/submissions/series/9999/images", 9999],
])("parseMangaBakaSeriesId(%p) = %p", (input, id) => {
expect(parseMangaBakaSeriesId(input)).toBe(id);
});
test.each(["", "abc", "https://example.org/9999", "https://mangabaka.org/manhwa/Tower-of-God", "0", "-5"])(
"parseMangaBakaSeriesId(%p) throws LinkError",
(input) => {
expect(() => parseMangaBakaSeriesId(input)).toThrow(LinkError);
},
);
test("parseLink adds https:// when the scheme is missing", () => {
expect(parseLink("www.webtoons.com/en/x/list?title_no=95").href).toBe("https://www.webtoons.com/en/x/list?title_no=95");
expect(() => parseLink(" ")).toThrow(LinkError);
});