Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/series/getters.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/works/work-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
});

Expand Down
487 changes: 487 additions & 0 deletions tests/mocks/data/series/1728802/index.html

Large diffs are not rendered by default.

665 changes: 665 additions & 0 deletions tests/mocks/data/series/2270465/index.html

Large diffs are not rendered by default.

688 changes: 688 additions & 0 deletions tests/mocks/data/series/2817877/index.html

Large diffs are not rendered by default.

424 changes: 424 additions & 0 deletions tests/mocks/data/series/2946579/index.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -17,5 +18,6 @@ export default [
nameHandlers,
workPageHandlers,
worksNavigateHandlers,
seriesHandlers,
allHandlers,
];
25 changes: 25 additions & 0 deletions tests/mocks/handlers/series/index.ts
Original file line number Diff line number Diff line change
@@ -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));
}
);
20 changes: 2 additions & 18 deletions tests/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"<p>My potentially related stories about the relationship between the OG Titans. Probably focused on Dick Grayson.</p>",
notes: null,
Expand Down Expand Up @@ -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",
],
});
});

Expand Down
8 changes: 7 additions & 1 deletion types/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkSummary["tags"], "warnings">;
Expand Down