-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathroutes.test.ts
More file actions
61 lines (51 loc) · 1.61 KB
/
Copy pathroutes.test.ts
File metadata and controls
61 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { env, exports } from "cloudflare:workers";
import { it } from "vitest";
import { upsertPost } from "../src/utils";
it("should create and read post", async ({ expect }) => {
let response = await exports.default.fetch("https://example.com/hello", {
method: "PUT",
body: "👋",
});
expect(response.status).toBe(204);
response = await exports.default.fetch("https://example.com/hello");
expect(response.status).toBe(200);
expect(await response.text()).toBe("👋");
});
it("should list posts", async ({ expect }) => {
await upsertPost(env, "/one", "1");
await upsertPost(env, "/two", "2");
await upsertPost(env, "/three", "3");
const response = await exports.default.fetch("https://example.com/");
expect(response.status).toBe(200);
expect(await response.text()).toMatchInlineSnapshot(`
"https://example.com/hello
👋
--------------------
https://example.com/one
1
--------------------
https://example.com/two
2
--------------------
https://example.com/three
3"
`);
});
it("should reject invalid method", async ({ expect }) => {
const response = await exports.default.fetch("https://example.com/hello", {
method: "POST",
body: "👋",
});
expect(response.status).toBe(405);
});
it("should respond with not found for invalid slugs", async ({ expect }) => {
const response = await exports.default.fetch("https://example.com/bad");
expect(response.status).toBe(404);
});
it("shouldn't allow creating post at root", async ({ expect }) => {
const response = await exports.default.fetch("https://example.com/", {
method: "PUT",
body: "👋",
});
expect(response.status).toBe(405);
});