From 085f49df350b20dc8206e26989163b2439b80648 Mon Sep 17 00:00:00 2001 From: nyaomaru Date: Sun, 29 Sep 2024 09:33:30 +0900 Subject: [PATCH 1/2] test: api --- tests/utils/api_test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/utils/api_test.ts diff --git a/tests/utils/api_test.ts b/tests/utils/api_test.ts new file mode 100644 index 0000000..3c80384 --- /dev/null +++ b/tests/utils/api_test.ts @@ -0,0 +1,33 @@ +import * as modAssertEqual from "https://deno.land/std@0.224.0/assert/assert_equals.ts"; +import * as modAssertThrows from "https://deno.land/std@0.224.0/assert/assert_throws.ts"; +import { getUserKey, handleUserNotFound, statusCheck } from "#src/utils/api.ts"; + +Deno.test("statusCheck", async (t) => { + await t.step("#1 throws error when status is falsy", () => { + modAssertThrows.assertThrows( + () => statusCheck(null as unknown as Deno.KvCommitResult), + Error, + "Something went wrong.", + ); + }); + + await t.step("#2 does not throw when status is truthy", () => { + const mockStatus = {} as Deno.KvCommitResult; + statusCheck(mockStatus); + }); +}); + +Deno.test("getUserKey returns correct user key", () => { + const id = "123"; + const expectedKey = ["user", "123"]; + modAssertEqual.assertEquals(getUserKey(id), expectedKey); +}); + +Deno.test("handleUserNotFound returns correct response", async () => { + const id = "123"; + const response = handleUserNotFound(id); + modAssertEqual.assertEquals(response.status, 200); + + const bodyText = await response.text(); + modAssertEqual.assertEquals(bodyText, `No user with id ${id} found`); +}); From 5399369505746fd994ab1990710667e19bcd816a Mon Sep 17 00:00:00 2001 From: nyaomaru Date: Sun, 29 Sep 2024 09:54:12 +0900 Subject: [PATCH 2/2] upgrade: fresh --- deno.json | 2 +- src/fresh.gen.ts | 2 +- tests/main_test.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 2ff3d4f..cedb91b 100644 --- a/deno.json +++ b/deno.json @@ -14,7 +14,7 @@ "exclude": ["**/_fresh/*"], "imports": { "#src/": "./src/", - "$fresh/": "https://deno.land/x/fresh@1.6.8/", + "$fresh/": "https://deno.land/x/fresh@1.7.1/", "$fresh_charts/": "https://deno.land/x/fresh_charts@0.3.1/", "$std/": "https://deno.land/std@0.216.0/", "$gfm": "jsr:@deno/gfm@^0.8.2", diff --git a/src/fresh.gen.ts b/src/fresh.gen.ts index ada6daf..5a20c67 100644 --- a/src/fresh.gen.ts +++ b/src/fresh.gen.ts @@ -29,7 +29,7 @@ import * as $Countdown from "./islands/Countdown.tsx"; import * as $Counter from "./islands/Counter.tsx"; import * as $MapIsland from "./islands/MapIsland.tsx"; import * as $NextContentButton from "./islands/NextContentButton.tsx"; -import { type Manifest } from "$fresh/server.ts"; +import type { Manifest } from "$fresh/server.ts"; const manifest = { routes: { diff --git a/tests/main_test.ts b/tests/main_test.ts index e276578..af78dcb 100644 --- a/tests/main_test.ts +++ b/tests/main_test.ts @@ -6,6 +6,7 @@ import * as modAssert from "https://deno.land/std@0.224.0/assert/assert.ts"; const CONN_INFO: ServeHandlerInfo = { remoteAddr: { hostname: "127.0.0.1", port: 8000, transport: "tcp" }, + completed: Promise.resolve(), }; const verifyPageContainsText = async (