formalize unit testing stuff and expose more metadata in Work

master
Drake 1 year ago
parent c1bfcddeab
commit 3723f1063a

@ -17,6 +17,10 @@
"https://deno.land/std@0.161.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c",
"https://deno.land/std@0.161.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832",
"https://deno.land/std@0.161.0/testing/asserts.ts": "1e340c589853e82e0807629ba31a43c84ebdcdeca910c4a9705715dfdb0f5ce8",
"https://deno.land/std@0.167.0/fmt/colors.ts": "03ad95e543d2808bc43c17a3dd29d25b43d0f16287fe562a0be89bf632454a12",
"https://deno.land/std@0.167.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c",
"https://deno.land/std@0.167.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832",
"https://deno.land/std@0.167.0/testing/asserts.ts": "51353e79437361d4b02d8e32f3fc83b22231bc8f8d4c841d86fd32b0b0afe940",
"https://deno.land/std@0.97.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58",
"https://deno.land/std@0.97.0/_util/os.ts": "e282950a0eaa96760c0cf11e7463e66babd15ec9157d4c9ed49cc0925686f6a7",
"https://deno.land/std@0.97.0/encoding/base64.ts": "eecae390f1f1d1cae6f6c6d732ede5276bf4b9cd29b1d281678c054dc5cc009e",

@ -1,7 +1,7 @@
import AO3 from "./src/classes/AO3.ts";
export default AO3;
export * from "./src/classes/AO3.ts";
export * from "./src/classes/Chapter.ts";
export * from "./src/classes/Search.ts";
export * from "./src/classes/Work.ts";
import Chapter from "./src/classes/Chapter.ts";
import Search from "./src/classes/Search.ts";
import Work from "./src/classes/Work.ts";
export { AO3, Chapter, Search, Work };

@ -67,7 +67,6 @@ export default class Chapter {
}
async init() {
console.log("initing chapter");
const res = await this.#session.get(
`/works/${this.#workID}/chapters/${this.#id}?view_adult=true`,
);
@ -112,7 +111,6 @@ export default class Chapter {
),
).forEach(
(t) => this.#text += (t as Element).innerText + "\n",
console.log(this.#text),
);
try {
this.#text = this.#text.trim();
@ -131,7 +129,6 @@ export default class Chapter {
),
).forEach(
(t) => this.#text += (t as Element).innerText + "\n",
console.log(this.#text),
);
}
}

@ -20,6 +20,10 @@ export default class Work {
id: ID;
#document: HTMLDocument;
#DOMParser: DOMParser;
/**
* the name of the work
*/
name = "";
/**
* a list of Chapters in the work
*/
@ -62,11 +66,17 @@ export default class Work {
//jank incarnate
async init() {
this.populateMetadata();
this.populateTags();
this.populateDates();
await this.populateChapters();
}
populateMetadata() {
this.name = (this.#document.querySelector("h2.title") as Element)
.innerText.trim();
}
populateTags() {
Array.from(
(this.#document.querySelector("dd.fandom > ul.commas") as Element)

@ -0,0 +1,47 @@
//FIXME: we need to test single-chapter works too (because those seem to be really inconsistent for some reason?)
import AO3 from "../mod.ts";
import { Work } from "../mod.ts";
import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts";
export default async function test(ao3: AO3) {
await Deno.test("chapters", async (test) => {
const work = await ao3.getWork("43251729");
await work.init();
assert(work.chapters.length > 0, "chapters array is not initialized");
await test.step("IDs", async () => {
assert(
await work.chapters[0].id === "108714198",
"incorrect chapter ID",
);
assert(
await work.chapters[0].workID === "43251729",
"incorrect work ID",
); //why do we even store the work's ID publicly in a chapter?
});
await test.step("name", async () => {
assert(
await work.chapters[0].name === "Welcome to the Studio",
"incorrect/missing chapter names",
);
});
await test.step("content", async () => {
//FIXME: this should probably be tested better
assert(
(await work.chapters[0].text).length > 0,
"text/content is completely missing",
);
});
await test.step("notes and summary", async () => {
//FIXME: write a chapter of my fic (lol) that includes a summary and end note for testing
assert(
await work.chapters[3].startNote ===
`If you haven't noticed yet, most of these chapters are named after Bendy fansongs
This is definitely because I'm trying to be smart and cool and make funny references, and definitely not because I'm uncreative :)`,
"incorrect start note parsing",
);
});
});
}

@ -0,0 +1,8 @@
import AO3 from "../src/classes/AO3.ts";
import workTest from "./work.ts";
import chaptersTest from "./chapter.ts";
const ao3 = new AO3();
await workTest(ao3);
await chaptersTest(ao3);

@ -0,0 +1,50 @@
import AO3 from "../mod.ts";
import type { Work } from "../mod.ts";
import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts";
export default async function test(ao3: AO3) {
await Deno.test("works", async (test) => {
let work: Work;
await test.step("initialization", async () => {
work = await ao3.getWork("43251729");
await work.init();
});
await test.step("tags", async (test) => {
assert(work.tags.length > 0, "Failed to parse any tags");
await test.step("fandoms", () => {
assert(
work.tags.includes("Bendy and the Ink Machine"),
"Failed to get correct fandom tags",
);
});
await test.step("characters", () => {
assert(
work.tags.includes("Bendy (Bendy and the Ink Machine)"),
"Failed to get correct character tags",
);
});
await test.step("ships", () => {
assert(
work.tags.includes(
"Bendy (Bendy and the Ink Machine)/Reader",
),
"Failed to get correct ship tags",
);
});
await test.step("freeforms", () => {
assert(
work.tags.includes("no beta read we die like sammy"),
"Failed to get correct freeform tags",
);
});
});
await test.step("other metadata", () => {
assert(
work.name === "Inky Desires [Bendy X Reader]",
"incorrect work name",
);
});
});
}
Loading…
Cancel
Save