diff --git a/package.json b/package.json index e186658..7b94202 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bobaboard/ao3.js", - "version": "0.10.0", + "version": "0.11.0", "description": "A NodeJS API for scraping AO3 data", "type": "module", "types": "./dist/index.d.ts", diff --git a/src/series/getters.ts b/src/series/getters.ts index 0d05030..bb9a725 100644 --- a/src/series/getters.ts +++ b/src/series/getters.ts @@ -1,7 +1,6 @@ import { Author, Series, SeriesWorkSummary } from "types/entities"; -import { SeriesPage, WorkPage } from "../page-loaders"; import { CheerioAPI, load } from "cheerio"; -import { getWorkDetailsFromUrl, getWorkUrl } from "src/urls"; +import { SeriesPage, WorkPage } from "../page-loaders"; import { getWorkBookmarkCount, getWorkHits, @@ -11,6 +10,7 @@ import { getWorkTotalChapters, getWorkWordCount, } from "src/works/work-getters"; +import { getWorkDetailsFromUrl, getWorkUrl } from "src/urls"; const monthMap: { [month: string]: string } = { Jan: "01", @@ -65,7 +65,7 @@ export const getSeriesDescription = ( export const getSeriesNotes = ($seriesPage: SeriesPage): string | null => { const notes = $seriesPage("dl.series dd:nth-of-type(5)"); if (notes.prevAll().first().text().trim() === "Notes:") { - return notes.html().trim(); + return notes.html()!.trim(); } else { return null; } @@ -136,7 +136,7 @@ const getSeriesWork = (workHtml: string): SeriesWorkSummary => { const publishedChapters = getWorkPublishedChapters($$work); const url = $work("a[href*='/works/']").attr("href") as string; - const id = getWorkDetailsFromUrl({ url }).workId + const id = getWorkDetailsFromUrl({ url }).workId; return { id, diff --git a/src/works/work-getters.ts b/src/works/work-getters.ts index 9bfe1e6..dfde02c 100644 --- a/src/works/work-getters.ts +++ b/src/works/work-getters.ts @@ -152,9 +152,9 @@ export const getWorkSeries = ($workPage: WorkPage): BasicSeries[] => { const link = seriesHtml.find("a:not(.next, .previous)"); series[index] = { - id: link.attr("href").replace("/series/", ""), + id: link.attr("href")!.replace("/series/", ""), name: link.text().trim(), - index: matches.length > 0 ? parseInt(matches[0]) : -1, + index: matches!.length > 0 ? parseInt(matches![0]) : -1, }; }); diff --git a/tests/mocks/data/series/1728802/index.html b/tests/mocks/data/series/1728802/index.html new file mode 100644 index 0000000..28ddaa9 --- /dev/null +++ b/tests/mocks/data/series/1728802/index.html @@ -0,0 +1,487 @@ + + + + + + + + + + + + + + + angsty oneshots/short stories - Anonymous - Marvel Cinematic Universe, Spider-Man (Tom Holland Movies) [Archive of Our Own] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ + + +
+
+ +

+angsty oneshots/short stories +

+ + + + +

Series Metadata

+
+
+
Creator:
+
Anonymous
+
Series Begun:
+
2020-05-03
+
Series Updated:
+
2020-06-08
+
Description:
+

basically just peter whump lmao

+
Stats:
+
+
+
Words:
+
24,722
+
Works:
+
3
+
Complete:
+
No
+
Bookmarks:
+
16
+
+
+
+
+

Listing Series

+ + + + +
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/mocks/data/series/2270465/index.html b/tests/mocks/data/series/2270465/index.html new file mode 100644 index 0000000..98ad3ae --- /dev/null +++ b/tests/mocks/data/series/2270465/index.html @@ -0,0 +1,665 @@ + + + + + + + + + + + + + + + OG Titan - MyHero - Batman - All Media Types, Nightwing (Comics), Red Hood and the Outlaws (Comics), Teen Titans (Comics), Titans (Comics) [Archive of Our Own] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ + + +
+
+ +

+OG Titan +

+ + + + +

Series Metadata

+
+
+
Creator:
+
+
Series Begun:
+
2021-04-11
+
Series Updated:
+
2023-02-13
+
Description:
+

My potentially related stories about the relationship between the OG Titans. Probably focused on Dick Grayson.

+
Stats:
+
+
+
Words:
+
30,044
+
Works:
+
6
+
Complete:
+
No
+
Bookmarks:
+
177
+
+
+
+
+

Listing Series

+ + + + +
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/mocks/data/series/2817877/index.html b/tests/mocks/data/series/2817877/index.html new file mode 100644 index 0000000..2291da7 --- /dev/null +++ b/tests/mocks/data/series/2817877/index.html @@ -0,0 +1,688 @@ + + + + + + + + + + + + + + + + + *Insert Fandom* but Social Media (one-shots) - Anonymous - Batman - All Media Types, Dream SMP RPF, Five Nights at Freddy's, Five Nights at Freddy's (Movie 2023), Marvel Cinematic Universe, Minecraft (Video Game), The Avengers (Marvel Movies), Turning Red (2022), Video Blogging RPF, 呪術廻戦 | Jujutsu Kaisen (Anime), 呪術廻戦 | Jujutsu Kaisen (Manga) [Archive of Our Own] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ + + +
+
+ +

+*Insert Fandom* but Social Media (one-shots) +

+ + + + +

Series Metadata

+
+
+
Creator:
+
Anonymous
+
Series Begun:
+
2021-10-29
+
Series Updated:
+
2023-11-01
+
Description:
+

Find out which series I am going to write a Social Media fic about *jazz hands*

+
Notes:
+

Part 1: Turning Red and Avengers fusion
Part 2-3: DSMP Fandom (2* is a Batman crossover)
Part 4: FNAF Fandom
Part 5: Jujutsu Kaisen

+
Stats:
+
+
+
Words:
+
16,938
+
Works:
+
5
+
Complete:
+
Yes
+
Bookmarks:
+
93
+
+
+
+
+

Listing Series

+ + + + +
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/mocks/data/series/2946579/index.html b/tests/mocks/data/series/2946579/index.html new file mode 100644 index 0000000..95c63b1 --- /dev/null +++ b/tests/mocks/data/series/2946579/index.html @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + Twitterchat Saga - Anonymous - Marvel Cinematic Universe, The Avengers (Marvel) - All Media Types [Archive of Our Own] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ + + +
+
+ +

+Twitterchat Saga +

+ + + + +

Series Metadata

+
+
+
Creator:
+
Anonymous
+
Series Begun:
+
2022-02-18
+
Series Updated:
+
2022-06-26
+
Stats:
+
+
+
Words:
+
30,585
+
Works:
+
2
+
Complete:
+
No
+
+
+
+
+

Listing Series

+ + + + +
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/mocks/handlers.ts b/tests/mocks/handlers.ts index c004f94..4141d3f 100644 --- a/tests/mocks/handlers.ts +++ b/tests/mocks/handlers.ts @@ -3,6 +3,7 @@ import allHandlers from "./handlers/all"; import feedHandlers from "./handlers/tags/feed"; import nameHandlers from "./handlers/tags/name"; import profileHandlers from "./handlers/users/profile"; +import seriesHandlers from "./handlers/series"; import tagWorksHandlers from "./handlers/tags/works"; import workPageHandlers from "./handlers/works"; import worksHandlers from "./handlers/works"; @@ -17,5 +18,6 @@ export default [ nameHandlers, workPageHandlers, worksNavigateHandlers, + seriesHandlers, allHandlers, ]; diff --git a/tests/mocks/handlers/series/index.ts b/tests/mocks/handlers/series/index.ts new file mode 100644 index 0000000..d80ec90 --- /dev/null +++ b/tests/mocks/handlers/series/index.ts @@ -0,0 +1,25 @@ +import { fileURLToPath } from "url"; +import filenamify from "filenamify"; +import fs from "fs"; +import path from "path"; +import { rest } from "msw"; + +const SERIES_DATA_DIR = path.resolve( + fileURLToPath(import.meta.url), + "../../../data/series" +); + +export default rest.all( + "https://archiveofourown.org/series/:series_id", + (req, res, ctx) => { + const html = fs.readFileSync( + path.resolve( + SERIES_DATA_DIR, + filenamify(req.params.series_id as string), + "index.html" + ) + ); + + return res(ctx.set("Content-Type", "text/html"), ctx.body(html)); + } +); diff --git a/tests/series.test.ts b/tests/series.test.ts index 5f935f1..e3998b9 100644 --- a/tests/series.test.ts +++ b/tests/series.test.ts @@ -9,9 +9,9 @@ describe("Fetches series information", () => { expect(series).toMatchObject({ id: "2270465", name: "OG Titan", - begunAt: "2021-04-11", + startedAt: "2021-04-11", updatedAt: "2023-02-13", - creators: [{ username: "MyHero", pseud: "MyHero" }], + authors: [{ username: "MyHero", pseud: "MyHero" }], description: "

My potentially related stories about the relationship between the OG Titans. Probably focused on Dick Grayson.

", notes: null, @@ -354,22 +354,6 @@ describe("Fetches series information", () => { stats: { bookmarks: 28, kudos: 242, hits: 1 }, }, ], - workTitles: [ - "Away from all of Reality", - "Code B", - "Donna Troy Loves You", - "Rockin Robin", - "Realistic Exit Strategy", - "You starting down the road leaving me again", - ], - workUrls: [ - "https://archiveofourown.org/works/30604247", - "https://archiveofourown.org/works/30794750", - "https://archiveofourown.org/works/30914645", - "https://archiveofourown.org/works/31221131", - "https://archiveofourown.org/works/35757790", - "https://archiveofourown.org/works/44149795", - ], }); }); diff --git a/types/entities.ts b/types/entities.ts index 49eea27..f27adb7 100644 --- a/types/entities.ts +++ b/types/entities.ts @@ -41,7 +41,13 @@ export interface User { export interface SeriesWorkSummary extends Omit< WorkSummary, - "category" | "publishedAt" | "rating" | "tags" | "stats" | "locked" + | "category" + | "publishedAt" + | "rating" + | "tags" + | "stats" + | "locked" + | "series" > { url: string; tags: Omit;