diff --git a/tests/routes/things/create.test.ts b/tests/routes/things/create.test.ts index 65e9935..6d81631 100644 --- a/tests/routes/things/create.test.ts +++ b/tests/routes/things/create.test.ts @@ -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() }) diff --git a/tests/routes/things/delete.test.ts b/tests/routes/things/delete.test.ts new file mode 100644 index 0000000..acdda6b --- /dev/null +++ b/tests/routes/things/delete.test.ts @@ -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) +})