Skip to content

Commit

Permalink
genres-test-cleanup (#30)
Browse files Browse the repository at this point in the history
genres tests cleanup
  • Loading branch information
wydengyre authored Jan 27, 2024
1 parent fe4453f commit d29c877
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/genres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import { NotFoundError } from "./error.js";
import { genresHtml } from "./genres.js";
import genresJson from "./test/generi.json" with { type: "json" };

test("genresHtml", async () => {
test("genres", async (t) => {
await t.test(genresHtmlSuccess);
await t.test(genresHtmlNotFound);
await t.test(genresHtml500);
});

async function genresHtmlSuccess() {
const fetchFn: typeof fetch = async (input) => {
assert.strictEqual(input.toString(), "https://rai.dev/generi.json");
return json(genresJson);
};
const conf = confWithFetch(fetchFn);

// just making sure this runs without error
const _html = await genresHtml(conf);
});
await genresHtml(conf);
}

test("genresHtml 404", async () => {
async function genresHtmlNotFound() {
const fetchFn: typeof fetch = async (input) => {
assert.strictEqual(input.toString(), "https://rai.dev/generi.json");
return new Response("Not found", { status: 404 });
Expand All @@ -26,9 +31,9 @@ test("genresHtml 404", async () => {
const expectedErr = new NotFoundError(new URL("https://rai.dev/generi.json"));
const p = genresHtml(conf);
await assert.rejects(p, expectedErr);
});
}

test("genresHtml 500", async () => {
async function genresHtml500() {
const fetchFn: typeof fetch = async (input) => {
assert.strictEqual(input.toString(), "https://rai.dev/generi.json");
return new Response("Internal Server Error", { status: 500 });
Expand All @@ -40,7 +45,7 @@ test("genresHtml 500", async () => {
);
const p = genresHtml(conf);
await assert.rejects(p, expectedErr);
});
}

const confWithFetch = (fetchFn: typeof fetch) => ({
baseUrl: new URL("https://test.dev/"),
Expand Down

0 comments on commit d29c877

Please sign in to comment.