From c10dedf7054e4ceeea5e55b199c35cba3c9ded06 Mon Sep 17 00:00:00 2001 From: Phan Van Bang Date: Sun, 14 Jun 2026 16:16:23 +0000 Subject: [PATCH 1/2] test: await ky.post and add delete route test - Fix create.test.ts: await ky.post() call and assert { ok: true } response - Add delete.test.ts: test create -> verify -> delete -> verify gone flow - Both tests use ky client properly with await Closes #2 --- tests/routes/things/create.test.ts | 8 ++++-- tests/routes/things/delete.test.ts | 41 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/routes/things/delete.test.ts diff --git a/tests/routes/things/create.test.ts b/tests/routes/things/create.test.ts index 65e9935..0874a86 100644 --- a/tests/routes/things/create.test.ts +++ b/tests/routes/things/create.test.ts @@ -4,16 +4,20 @@ import { test, expect } from "bun:test" test("create a thing", async () => { const { ky } = await getTestServer() - ky.post("things/create", { + const createRes = await ky.post("things/create", { json: { name: "Thing1", description: "Thing1 Description", }, - }) + }).json<{ ok: boolean }>() + + expect(createRes.ok).toBe(true) const data = await ky .get("things/list") .json<{ things: { name: string; description: string }[] }>() expect(data.things).toHaveLength(1) + expect(data.things[0].name).toBe("Thing1") + expect(data.things[0].description).toBe("Thing1 Description") }) diff --git a/tests/routes/things/delete.test.ts b/tests/routes/things/delete.test.ts new file mode 100644 index 0000000..e61e98c --- /dev/null +++ b/tests/routes/things/delete.test.ts @@ -0,0 +1,41 @@ +import { getTestServer } from "tests/fixtures/get-test-server" +import { test, expect } from "bun:test" + +test("delete a thing", async () => { + const { ky } = await getTestServer() + + // Create a thing first + const createRes = await ky.post("things/create", { + json: { + name: "ThingToDelete", + description: "Will be deleted", + }, + }).json<{ ok: boolean }>() + + expect(createRes.ok).toBe(true) + + // Verify it exists + const listBefore = await ky + .get("things/list") + .json<{ things: { thing_id: string; name: string }[] }>() + + expect(listBefore.things).toHaveLength(1) + const thingId = listBefore.things[0].thing_id + + // Delete the thing using URL-encoded form data + const deleteRes = await ky.post("things/delete", { + body: new URLSearchParams({ thing_id: thingId }), + headers: { + "content-type": "application/x-www-form-urlencoded", + }, + }).json<{ ok: boolean }>() + + expect(deleteRes.ok).toBe(true) + + // Verify it's gone + const listAfter = await ky + .get("things/list") + .json<{ things: { thing_id: string; name: string }[] }>() + + expect(listAfter.things).toHaveLength(0) +}) From cc5e3c32b5fca2739aa8b2f46c3e6ea2dbe8eaeb Mon Sep 17 00:00:00 2001 From: Phan Van Bang Date: Sun, 14 Jun 2026 17:32:33 +0000 Subject: [PATCH 2/2] fix: correct biome config key and apply formatting --- biome.json | 2 +- lib/admin/Table.tsx | 12 +++++++++--- lib/middleware/with-ctx-react.tsx | 8 ++++++-- tests/routes/things/create.test.ts | 14 ++++++++------ tests/routes/things/delete.test.ts | 28 ++++++++++++++++------------ 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/biome.json b/biome.json index 75bde2b..2c8ea73 100644 --- a/biome.json +++ b/biome.json @@ -14,7 +14,7 @@ "formatter": { "jsxQuoteStyle": "double", "quoteProperties": "asNeeded", - "trailingCommas": "all", + "trailingComma": "all", "semicolons": "asNeeded", "arrowParentheses": "always", "bracketSpacing": true, diff --git a/lib/admin/Table.tsx b/lib/admin/Table.tsx index 03f0a58..6937b47 100644 --- a/lib/admin/Table.tsx +++ b/lib/admin/Table.tsx @@ -45,7 +45,9 @@ const Cell = ({ {cellValue.map((id: string, index: number) => ( {id?.split("-")?.[0]}... @@ -60,7 +62,9 @@ const Cell = ({ const resource = pluralize(columnKey.slice(0, -3)) // e.g., "account_id" -> "accounts" return ( {cellValue?.split("-")?.[0]} @@ -98,7 +102,9 @@ const Cell = ({ contentType = "application/json" } else if (typeof cellValue === "string") { b64 = Buffer.from(cellValue).toString("base64") - filename = `${columnKey.split("_").slice(0, -1).join("_")}.${columnKey.split("_").pop()}` + filename = `${columnKey.split("_").slice(0, -1).join("_")}.${columnKey + .split("_") + .pop()}` contentType = "application/octet-stream" } else { throw new Error(`Unknown cell value type: ${typeof cellValue}`) diff --git a/lib/middleware/with-ctx-react.tsx b/lib/middleware/with-ctx-react.tsx index 1075b5d..18fcda8 100644 --- a/lib/middleware/with-ctx-react.tsx +++ b/lib/middleware/with-ctx-react.tsx @@ -51,7 +51,9 @@ button { / {component} @@ -74,7 +76,9 @@ button { onchange="document.cookie = 'timezone=' + this.value + ';path=/'; location.reload();" > - + `, diff --git a/tests/routes/things/create.test.ts b/tests/routes/things/create.test.ts index 0874a86..5f21b45 100644 --- a/tests/routes/things/create.test.ts +++ b/tests/routes/things/create.test.ts @@ -4,12 +4,14 @@ import { test, expect } from "bun:test" test("create a thing", async () => { const { ky } = await getTestServer() - const createRes = await ky.post("things/create", { - json: { - name: "Thing1", - description: "Thing1 Description", - }, - }).json<{ ok: boolean }>() + const createRes = await ky + .post("things/create", { + json: { + name: "Thing1", + description: "Thing1 Description", + }, + }) + .json<{ ok: boolean }>() expect(createRes.ok).toBe(true) diff --git a/tests/routes/things/delete.test.ts b/tests/routes/things/delete.test.ts index e61e98c..611aa4e 100644 --- a/tests/routes/things/delete.test.ts +++ b/tests/routes/things/delete.test.ts @@ -5,12 +5,14 @@ test("delete a thing", async () => { const { ky } = await getTestServer() // Create a thing first - const createRes = await ky.post("things/create", { - json: { - name: "ThingToDelete", - description: "Will be deleted", - }, - }).json<{ ok: boolean }>() + const createRes = await ky + .post("things/create", { + json: { + name: "ThingToDelete", + description: "Will be deleted", + }, + }) + .json<{ ok: boolean }>() expect(createRes.ok).toBe(true) @@ -23,12 +25,14 @@ test("delete a thing", async () => { const thingId = listBefore.things[0].thing_id // Delete the thing using URL-encoded form data - const deleteRes = await ky.post("things/delete", { - body: new URLSearchParams({ thing_id: thingId }), - headers: { - "content-type": "application/x-www-form-urlencoded", - }, - }).json<{ ok: boolean }>() + const deleteRes = await ky + .post("things/delete", { + body: new URLSearchParams({ thing_id: thingId }), + headers: { + "content-type": "application/x-www-form-urlencoded", + }, + }) + .json<{ ok: boolean }>() expect(deleteRes.ok).toBe(true)