Skip to content

Commit

Permalink
Test 404 under /snapshot (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev authored Jan 5, 2025
1 parent e1583a7 commit 0313c04
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for (const hostAddress of [
"http://localhost:3000",
"https://localhost:3001",
] as const) {
describe("/snapshot", () => {
describe(`${hostAddress.slice(0, hostAddress.indexOf("/") - 1)}: /snapshot`, () => {
const snapshotFirstPathComp = "snapshot" as const;
for (const [name, path] of [
["valid with a one-level subdir", "2025-01-02/a"],
Expand Down Expand Up @@ -53,5 +53,36 @@ for (const hostAddress of [
);
});
}

for (const [name, path] of [
["non-existing with no subdir", "non-existing"],
[
"non-existing with no subdir but with a trailing slash",
"non-existing/",
],
["non-existing with a one-level subdir", "non-existing/a"],
[
"non-existing with a one-level subdir with a trailing slash",
"non-existing/a/",
],
["non-existing with a two-level subdir", "non-existing/a/b"],
[
"non-existing with a two-level subdir with a trailing slash",
"non-existing/a/b/",
],
] as const) {
test(`Return 404 with invalid URL under /shapshot: ${name}`, async () => {
const response = await fetch(
`${hostAddress}/${snapshotFirstPathComp}/${path}`,
{
redirect: "manual",
},
);

expect(response.status).toBe(404);
expect(response.headers.get("content-type")).toContain("text/plain");
expect(await response.text()).toBe("404 Not Found");
});
}
});
}

0 comments on commit 0313c04

Please sign in to comment.