add tests + some stuff
parent
c4bb5cc152
commit
8b331edc54
@ -1,19 +0,0 @@
|
|||||||
import Wattpad from "./mod.ts";
|
|
||||||
|
|
||||||
const wp = new Wattpad();
|
|
||||||
|
|
||||||
/*const search = wp.search({
|
|
||||||
query: "bendy x reader",
|
|
||||||
});*/
|
|
||||||
|
|
||||||
const search = wp.tagSearch({
|
|
||||||
tags: [
|
|
||||||
"bendyxreader",
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
await search.update(0);
|
|
||||||
|
|
||||||
await search.results[0].init();
|
|
||||||
|
|
||||||
console.log(search.results[0]);
|
|
@ -0,0 +1,50 @@
|
|||||||
|
import Wattpad from "../mod.ts";
|
||||||
|
import {
|
||||||
|
assert,
|
||||||
|
AssertionError,
|
||||||
|
} from "https://deno.land/std@0.167.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
export default function test(watt: Wattpad) {
|
||||||
|
Deno.test("chapters", async (test) => {
|
||||||
|
const work = watt.getStory("327425279");
|
||||||
|
await work.init();
|
||||||
|
|
||||||
|
await test.step("initialization", async () => {
|
||||||
|
assert(
|
||||||
|
work.chapters.length > 0,
|
||||||
|
"chapters array is not initialized",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await work.chapters[0].init();
|
||||||
|
await work.chapters[3].init();
|
||||||
|
} catch {
|
||||||
|
throw new AssertionError("failed to initialize chapters");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step("IDs", () => {
|
||||||
|
assert(
|
||||||
|
work.chapters[0].id === "1288785987",
|
||||||
|
"incorrect chapter ID",
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
work.chapters[0].workID === "327425279",
|
||||||
|
"incorrect work ID",
|
||||||
|
); //why do we even store the work's ID publicly in a chapter?
|
||||||
|
});
|
||||||
|
await test.step("name", () => {
|
||||||
|
assert(
|
||||||
|
work.chapters[0].name === "Chapter 1 - Welcome to the Studio",
|
||||||
|
"incorrect/missing chapter names",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await test.step("content", () => {
|
||||||
|
//FIXME: this should probably be tested better
|
||||||
|
assert(
|
||||||
|
(work.chapters[0].text).length > 0,
|
||||||
|
"text/content is completely missing",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import Wattpad from "../src/classes/Wattpad.ts";
|
||||||
|
import workTest from "./story.ts";
|
||||||
|
import chaptersTest from "./chapter.ts";
|
||||||
|
import searchTest from "./search.ts";
|
||||||
|
|
||||||
|
const wattpad = new Wattpad();
|
||||||
|
|
||||||
|
workTest(wattpad);
|
||||||
|
chaptersTest(wattpad);
|
||||||
|
searchTest(wattpad);
|
@ -0,0 +1,66 @@
|
|||||||
|
import Wattpad from "../mod.ts";
|
||||||
|
import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
export default function test(watt: Wattpad) {
|
||||||
|
Deno.test("normal searches", async (test) => {
|
||||||
|
await test.step("specific search", async () => {
|
||||||
|
const search = watt.search({
|
||||||
|
query: "Inky Desires [Bendy x Reader]",
|
||||||
|
}); // if a search for the exact name of my fic doesn't return the fic i will shit myself
|
||||||
|
|
||||||
|
await search.update(0);
|
||||||
|
|
||||||
|
await search.results[0].init();
|
||||||
|
|
||||||
|
assert(
|
||||||
|
search.results[0].id === "327425279",
|
||||||
|
"incorrect work found",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await test.step("broad search", async () => {
|
||||||
|
const search = watt.search({
|
||||||
|
query: "huggy wuggy smut",
|
||||||
|
});
|
||||||
|
|
||||||
|
await search.update(0);
|
||||||
|
|
||||||
|
assert(search.results.length == 30, "not enough search results");
|
||||||
|
|
||||||
|
await search.update(1);
|
||||||
|
assert(
|
||||||
|
search.results.length == 30,
|
||||||
|
"could not find second page of results",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Deno.test("tag searches", async (test) => {
|
||||||
|
await test.step("specific search", async () => {
|
||||||
|
const search = watt.tagSearch({
|
||||||
|
tags: ["bluesourpachkid"],
|
||||||
|
}); // if somebody else uses this exact tag (including misspelling) i will also shit myself
|
||||||
|
|
||||||
|
await search.update(0);
|
||||||
|
|
||||||
|
await search.results[0].init();
|
||||||
|
|
||||||
|
assert(
|
||||||
|
search.results[0].id === "290528000",
|
||||||
|
"incorrect work found",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await test.step("broad search", async () => {
|
||||||
|
const search = watt.tagSearch({
|
||||||
|
tags: ["batim", "bendyxreader"],
|
||||||
|
});
|
||||||
|
|
||||||
|
await search.update(0);
|
||||||
|
assert(search.results.length == 20, "not enough search results");
|
||||||
|
|
||||||
|
await search.update(1);
|
||||||
|
assert(
|
||||||
|
search.results.length == 20,
|
||||||
|
"could not find second page of results",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import Wattpad from "../mod.ts";
|
||||||
|
import type { Story } from "../mod.ts";
|
||||||
|
import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
export default function test(watt: Wattpad) {
|
||||||
|
Deno.test("stories", async (test) => {
|
||||||
|
let work: Story;
|
||||||
|
await test.step("initialization", async () => {
|
||||||
|
work = watt.getStory("327425279");
|
||||||
|
await work.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step("tags", () => {
|
||||||
|
assert(work.tags.length > 0, "Failed to parse any tags");
|
||||||
|
assert(
|
||||||
|
work.tags.includes("bendyxreader"),
|
||||||
|
"Failed to get correct tags",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step("other metadata", () => {
|
||||||
|
assert(
|
||||||
|
work.name === "Inky Desires [Bendy X Reader]",
|
||||||
|
"incorrect work name",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue