Skip to content

Commit

Permalink
Merge pull request #28 from nyaomaru/add-test-2
Browse files Browse the repository at this point in the history
Add test 2
  • Loading branch information
nyaomaru authored Sep 29, 2024
2 parents 110fe2d + 5399369 commit 7eaa41c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions tests/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
33 changes: 33 additions & 0 deletions tests/utils/api_test.ts
Original file line number Diff line number Diff line change
@@ -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`);
});

0 comments on commit 7eaa41c

Please sign in to comment.