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
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"trailingComma": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
12 changes: 9 additions & 3 deletions lib/admin/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const Cell = ({
{cellValue.map((id: string, index: number) => (
<a
key={index}
href={`/admin/${removeResourcePrefixes(resource)}/get?${removeResourcePrefixes(columnKey.slice(0, -1))}=${id}`}
href={`/admin/${removeResourcePrefixes(
resource,
)}/get?${removeResourcePrefixes(columnKey.slice(0, -1))}=${id}`}
className="text-blue-500 hover:underline"
>
{id?.split("-")?.[0]}...
Expand All @@ -60,7 +62,9 @@ const Cell = ({
const resource = pluralize(columnKey.slice(0, -3)) // e.g., "account_id" -> "accounts"
return (
<a
href={`/admin/${removeResourcePrefixes(pluralize(resource))}/get?${removeResourcePrefixes(columnKey)}=${cellValue}`}
href={`/admin/${removeResourcePrefixes(
pluralize(resource),
)}/get?${removeResourcePrefixes(columnKey)}=${cellValue}`}
>
{cellValue?.split("-")?.[0]}
</a>
Expand Down Expand Up @@ -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}`)
Expand Down
8 changes: 6 additions & 2 deletions lib/middleware/with-ctx-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ button {
<span key={index}>
<span className="px-0.5 text-gray-500">/</span>
<a
href={`/${pathComponents.slice(0, index + 1).join("/")}`}
href={`/${pathComponents
.slice(0, index + 1)
.join("/")}`}
>
{component}
</a>
Expand All @@ -74,7 +76,9 @@ button {
onchange="document.cookie = 'timezone=' + this.value + ';path=/'; location.reload();"
>
<option ${timezone === "UTC" ? "selected" : ""} value="UTC">UTC</option>
<option ${timezone === "America/Los_Angeles" ? "selected" : ""} value="America/Los_Angeles">Pacific</option>
<option ${
timezone === "America/Los_Angeles" ? "selected" : ""
} value="America/Los_Angeles">Pacific</option>
<option ${timezone === "Asia/Kolkata" ? "selected" : ""} value="Asia/Kolkata">IST</option>
</select>
`,
Expand Down
18 changes: 12 additions & 6 deletions tests/routes/things/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ 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 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")
})
45 changes: 45 additions & 0 deletions tests/routes/things/delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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)
})
Loading