Skip to content

Commit ece7dfe

Browse files
Essential Randomnessessential-randomness
authored andcommitted
add mocks for work navigation page
1 parent d43010c commit ece7dfe

File tree

3 files changed

+308
-0
lines changed

3 files changed

+308
-0
lines changed

tests/mocks/data/works/43703871/navigate.html

Lines changed: 279 additions & 0 deletions
Large diffs are not rendered by default.

tests/mocks/handlers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { RestHandler } from "msw";
12
import allHandlers from "./handlers/all";
23
import feedHandlers from "./handlers/tags/feed";
34
import nameHandlers from "./handlers/tags/name";
45
import profileHandlers from "./handlers/users/profile";
56
import tagWorksHandlers from "./handlers/tags/works";
67
import workPageHandlers from "./handlers/works";
78
import worksHandlers from "./handlers/works";
9+
// TODO: export these directly from worksHandlers
10+
import worksNavigateHandlers from "./handlers/works/navigate";
811

912
export default [
1013
profileHandlers,
@@ -13,5 +16,6 @@ export default [
1316
worksHandlers,
1417
nameHandlers,
1518
workPageHandlers,
19+
worksNavigateHandlers,
1620
allHandlers,
1721
];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { fileURLToPath } from "url";
2+
import filenamify from "filenamify";
3+
import fs from "fs";
4+
import path from "path";
5+
import { rest } from "msw";
6+
7+
const WORKS_DATA_DIR = path.resolve(
8+
fileURLToPath(import.meta.url),
9+
"../../../data/works"
10+
);
11+
12+
export default rest.all(
13+
"https://archiveofourown.org/works/:work_id/navigate",
14+
(req, res, ctx) => {
15+
const html = fs.readFileSync(
16+
path.resolve(
17+
WORKS_DATA_DIR,
18+
filenamify(req.params.work_id as string),
19+
"navigate.html"
20+
)
21+
);
22+
23+
return res(ctx.set("Content-Type", "text/html"), ctx.body(html));
24+
}
25+
);

0 commit comments

Comments
 (0)