Skip to content

Commit 579c8de

Browse files
test: tighten ky things route coverage
1 parent 1ec84a1 commit 579c8de

3 files changed

Lines changed: 85 additions & 2 deletions

File tree

tests/routes/things/create.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ test("create a thing", async () => {
1717

1818
const data = await ky
1919
.get("things/list")
20-
.json<{ things: { name: string; description: string }[] }>()
20+
.json<{ things: { thing_id: string; name: string; description: string }[] }>()
2121

22-
expect(data.things).toHaveLength(1)
22+
expect(data.things).toEqual([
23+
{
24+
thing_id: "0",
25+
name: "Thing1",
26+
description: "Thing1 Description",
27+
},
28+
])
2329
})

tests/routes/things/delete.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,34 @@ test("delete a thing", async () => {
4040

4141
expect(listAfter.things).toHaveLength(0)
4242
})
43+
44+
test("delete is a no-op for unknown thing ids", async () => {
45+
const { ky } = await getTestServer()
46+
47+
await ky.post("things/create", {
48+
json: {
49+
name: "Thing1",
50+
description: "Thing1 Description",
51+
},
52+
})
53+
54+
const deleteResponse = await ky
55+
.post("things/delete", {
56+
body: new URLSearchParams({ thing_id: "missing" }),
57+
})
58+
.json<{ ok: boolean }>()
59+
60+
expect(deleteResponse).toEqual({ ok: true })
61+
62+
const data = await ky.get("things/list").json<{
63+
things: { thing_id: string; name: string; description: string }[]
64+
}>()
65+
66+
expect(data.things).toEqual([
67+
{
68+
thing_id: "0",
69+
name: "Thing1",
70+
description: "Thing1 Description",
71+
},
72+
])
73+
})

tests/routes/things/list.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { expect, test } from "bun:test"
2+
import { getTestServer } from "tests/fixtures/get-test-server"
3+
4+
test("list starts empty", async () => {
5+
const { ky } = await getTestServer()
6+
7+
const data = await ky.get("things/list").json<{
8+
things: { thing_id: string; name: string; description: string }[]
9+
}>()
10+
11+
expect(data.things).toEqual([])
12+
})
13+
14+
test("list preserves insertion order and generated ids", async () => {
15+
const { ky } = await getTestServer()
16+
17+
await ky.post("things/create", {
18+
json: {
19+
name: "Thing1",
20+
description: "Thing1 Description",
21+
},
22+
})
23+
await ky.post("things/create", {
24+
json: {
25+
name: "Thing2",
26+
description: "Thing2 Description",
27+
},
28+
})
29+
30+
const data = await ky.get("things/list").json<{
31+
things: { thing_id: string; name: string; description: string }[]
32+
}>()
33+
34+
expect(data.things).toEqual([
35+
{
36+
thing_id: "0",
37+
name: "Thing1",
38+
description: "Thing1 Description",
39+
},
40+
{
41+
thing_id: "1",
42+
name: "Thing2",
43+
description: "Thing2 Description",
44+
},
45+
])
46+
})

0 commit comments

Comments
 (0)