Skip to content
Closed
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
28 changes: 19 additions & 9 deletions tests/routes/things/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import { test, expect } from "bun:test"
test("create a thing", async () => {
const { ky } = await getTestServer()

ky.post("things/create", {
json: {
const createResponse = await ky
.post("things/create", {
json: {
name: "Thing1",
description: "Thing1 Description",
},
})
.json<{ ok: boolean }>()

expect(createResponse).toEqual({ ok: true })

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

expect(data.things).toEqual([
{
thing_id: "0",
name: "Thing1",
description: "Thing1 Description",
},
})

const data = await ky
.get("things/list")
.json<{ things: { name: string; description: string }[] }>()

expect(data.things).toHaveLength(1)
])
})
70 changes: 70 additions & 0 deletions tests/routes/things/delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { expect, test } from "bun:test"
import { getTestServer } from "tests/fixtures/get-test-server"

test("delete a thing with ky form data", async () => {
const { ky } = await getTestServer()

await ky.post("things/create", {
json: {
name: "Thing1",
description: "Thing1 Description",
},
})
await ky.post("things/create", {
json: {
name: "Thing2",
description: "Thing2 Description",
},
})

const deleteResponse = await ky
.post("things/delete", {
body: new URLSearchParams({ thing_id: "0" }),
})
.json<{ ok: boolean }>()

expect(deleteResponse).toEqual({ ok: true })

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

expect(data.things).toEqual([
{
thing_id: "1",
name: "Thing2",
description: "Thing2 Description",
},
])
})

test("delete is a no-op for unknown thing ids", async () => {
const { ky } = await getTestServer()

await ky.post("things/create", {
json: {
name: "Thing1",
description: "Thing1 Description",
},
})

const deleteResponse = await ky
.post("things/delete", {
body: new URLSearchParams({ thing_id: "missing" }),
})
.json<{ ok: boolean }>()

expect(deleteResponse).toEqual({ ok: true })

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

expect(data.things).toEqual([
{
thing_id: "0",
name: "Thing1",
description: "Thing1 Description",
},
])
})
46 changes: 46 additions & 0 deletions tests/routes/things/list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect, test } from "bun:test"
import { getTestServer } from "tests/fixtures/get-test-server"

test("list starts empty", async () => {
const { ky } = await getTestServer()

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

expect(data.things).toEqual([])
})

test("list preserves insertion order and generated ids", async () => {
const { ky } = await getTestServer()

await ky.post("things/create", {
json: {
name: "Thing1",
description: "Thing1 Description",
},
})
await ky.post("things/create", {
json: {
name: "Thing2",
description: "Thing2 Description",
},
})

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

expect(data.things).toEqual([
{
thing_id: "0",
name: "Thing1",
description: "Thing1 Description",
},
{
thing_id: "1",
name: "Thing2",
description: "Thing2 Description",
},
])
})
Loading