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

ky.post("things/create", {
json: {
name: "Thing1",
description: "Thing1 Description",
},
})
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: { name: string; description: string }[] }>()
const data = await ky.get("things/list").json<{
things: { thing_id: string; name: string; description: string }[]
}>()

expect(data.things).toHaveLength(1)
expect(data.things[0]).toMatchObject({
name: "Thing1",
description: "Thing1 Description",
})
expect(data.things[0]?.thing_id).toBeString()
})
37 changes: 37 additions & 0 deletions tests/routes/things/delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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()
const name = `Thing to delete ${crypto.randomUUID()}`

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

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

const thingId = beforeDelete.things.find(
(thing) => thing.name === name,
)?.thing_id
expect(thingId).toBeString()

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

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

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

expect(afterDelete.things.some((thing) => thing.name === name)).toBe(false)
})
Loading