diff --git a/node-build.ts b/node-build.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/classes/Wattpad.ts b/src/classes/Wattpad.ts index bec42dc..2a3a7d7 100644 --- a/src/classes/Wattpad.ts +++ b/src/classes/Wattpad.ts @@ -1,4 +1,4 @@ -import Work from "./Story.ts"; +import Story from "./Story.ts"; import Search, { SearchParameters as QuerySearchParams } from "./Search.ts"; import TagSearch, { SearchParameters as TagSearchParams } from "./TagSearch.ts"; import { newSession, Options } from "../utils/http.ts"; @@ -22,10 +22,10 @@ export default class Wattpad { /** * gets a Story from an ID - * @returns {Promise} a Work class for the work + * @returns {Promise} a Story class for the story */ - async getWork(id: string): Promise { - return new Work(id, this.session); + getStory(id: string): Story { + return new Story(id, this.session); } search(opts: QuerySearchParams) { diff --git a/test.ts b/test.ts deleted file mode 100644 index 2a2b552..0000000 --- a/test.ts +++ /dev/null @@ -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]); diff --git a/tests/chapter.ts b/tests/chapter.ts new file mode 100644 index 0000000..5727eaa --- /dev/null +++ b/tests/chapter.ts @@ -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", + ); + }); + }); +} diff --git a/tests/index.ts b/tests/index.ts new file mode 100644 index 0000000..c81f585 --- /dev/null +++ b/tests/index.ts @@ -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); diff --git a/tests/search.ts b/tests/search.ts new file mode 100644 index 0000000..e6b79ed --- /dev/null +++ b/tests/search.ts @@ -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", + ); + }); + }); +} diff --git a/tests/story.ts b/tests/story.ts new file mode 100644 index 0000000..873ad91 --- /dev/null +++ b/tests/story.ts @@ -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", + ); + }); + }); +}