From ee85b6fe5e94ab65fc5a5f5c3c1cf5bdb2965e0b Mon Sep 17 00:00:00 2001
From: Matt Leon <108271225+wydengyre@users.noreply.github.com>
Date: Sat, 27 Jan 2024 17:45:55 +0700
Subject: [PATCH] handler-test-cleanup (#32)
handler test cleanup
---
lib/handler.test.ts | 50 ++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/lib/handler.test.ts b/lib/handler.test.ts
index f3694cb..d42df3d 100644
--- a/lib/handler.test.ts
+++ b/lib/handler.test.ts
@@ -8,6 +8,15 @@ import expectedJson from "./test/lastoriaingiallo.parsed.json" with {
};
import { parseFeed } from "./test/parse-feed.js";
+test("handler", async (t) => {
+ await t.test(indexSucccess);
+ await t.test(rssFeedSuccess);
+ await t.test(rssFeedFail404);
+ await t.test(rssFeedFail500);
+ await t.test(rssFeedFailCorrupt);
+ await t.test(notFound);
+});
+
const baseUrl = new URL("https://test.dev/");
const raiBaseUrl = new URL("https://rai.dev/");
@@ -19,7 +28,7 @@ const fetchHandler = mkFetchHandler({
logger: logger.disabled,
});
-test("index", async () => {
+async function indexSucccess() {
const req = new Request("arbitrary://arbitrary/");
const resp = await fetchHandler(req);
@@ -27,45 +36,48 @@ test("index", async () => {
assert.strictEqual(resp.headers.get("Content-Language"), "it");
const _text = await resp.text();
// TODO: check validity of HTML
-});
+}
-test("rss feed success", async () => {
- const req = new Request("https://test.dev/programmi/lastoriaingiallo.xml");
+async function rssFeedSuccess() {
+ const req = new Request(
+ "arbitrary://arbitrary/programmi/lastoriaingiallo.xml",
+ );
const resp = await fetchHandler(req);
assert.strictEqual(resp.status, 200);
const feed = await resp.text();
const parsedFeed = parseFeed(feed);
assert.deepStrictEqual(parsedFeed, expectedJson);
-});
+}
-test("rss feed failure: 404 from RAI server", async () => {
- const req = new Request("https://test.dev/programmi/nonexistent.xml");
+async function rssFeedFail404() {
+ const req = new Request("arbitrary://arbitrary/programmi/nonexistent.xml");
const resp = await fetchHandler(req);
+
assert.strictEqual(resp.status, 404);
- assert.strictEqual(resp.headers.get("Content-Type"), "application/xml");
const text = await resp.text();
assert.strictEqual(
text,
"404
Not Found",
);
-});
+}
-test("rss feed failure: 500 from RAI server", async () => {
- const req = new Request("https://test.dev/programmi/500.xml");
+async function rssFeedFail500() {
+ const req = new Request("arbitrary://arbitrary/programmi/500.xml");
const resp = await fetchHandler(req);
+
assert.strictEqual(resp.status, 500);
- assert.strictEqual(resp.headers.get("Content-Type"), "application/xml");
const text = await resp.text();
assert.strictEqual(
text,
"500
server error",
);
-});
+}
-test("rss feed failure: failure to process RAI json feed", async () => {
- const req = new Request("https://test.dev/programmi/corrupt.xml");
+async function rssFeedFailCorrupt() {
+ const req = new Request("arbitrary://arbitrary/programmi/corrupt.xml");
const resp = await fetchHandler(req);
+
assert.strictEqual(resp.status, 500);
assert.strictEqual(resp.headers.get("Content-Type"), "application/xml");
const text = await resp.text();
@@ -73,13 +85,13 @@ test("rss feed failure: failure to process RAI json feed", async () => {
text,
"500
server error",
);
-});
+}
-test("404", async () => {
- const req = new Request("https://test.dev/nonexistent");
+async function notFound() {
+ const req = new Request("arbitrary://arbitrary/nonexistent");
const resp = await fetchHandler(req);
assert.strictEqual(resp.status, 404);
const text = await resp.text();
assert.strictEqual(text, "Not found.");
-});
+}