feat: Add unit-tests #25

Merged
timharek merged 31 commits from feature-testing into main 2024-04-11 19:10:16 +00:00
2 changed files with 9 additions and 7 deletions
Showing only changes of commit 93d11a56b1 - Show all commits

View File

@ -45,11 +45,11 @@ async function withDownloadLink(
}
}
// TODO: Replace throws with `console.error` and return `null` if bad response.
export const nrkRadio = {
search: async (query: string): Promise<SearchResultList> => {
search: async (query: string): Promise<SearchResultList | null> => {
if (query === "") {
throw "Empty search query.";
console.error("Empty search query.");
return null;
}
const { status, body } = await get<
searchComponents["schemas"]["searchresult"]
@ -57,7 +57,9 @@ export const nrkRadio = {
if (status === STATUS_CODE.OK && body) {
return body.results.series?.results;
}
throw `Something went wrong with ${query} - got status ${status}`;
console.error(`Something went wrong with ${query} - got status ${status}`);
return null;
},
getSerieData: async (seriesId: string) => {
let [

View File

@ -1,5 +1,4 @@
import { assertEquals } from "$std/assert/assert_equals.ts";
import { assertRejects } from "$std/assert/assert_rejects.ts";
import { nrkRadio } from "./nrk.ts";
import { assertGreaterOrEqual } from "$std/assert/assert_greater_or_equal.ts";
import { assertExists } from "https://deno.land/std@0.216.0/assert/assert_exists.ts";
@ -12,8 +11,9 @@ Deno.test("Verify search query `trygd` returns one result: 'Trygdekontoret'", as
assertEquals(result[0].seriesId, "trygdekontoret");
});
Deno.test("Verify empty search query yields error", async () => {
await assertRejects(async () => await nrkRadio.search(""));
Deno.test("Verify empty search query yields `null`", async () => {
const result = await nrkRadio.search("");
assertEquals(result, null);
});
Deno.test("Verify getting series data for 'trygdekontoret' works", async () => {