kill-the-newsletter/src/test.ts

31 lines
843 B
TypeScript
Raw Normal View History

2020-03-19 01:58:41 +01:00
import { webServer, redirectServer, feedPath } from ".";
2020-03-19 01:16:00 +01:00
import fetch from "node-fetch";
2020-03-18 20:33:10 +01:00
import fs from "fs";
2020-03-18 20:21:44 +01:00
2020-03-19 01:58:41 +01:00
test("webServer", async () => {
2020-03-19 01:16:00 +01:00
const response = await fetch("http://localhost:8443", {
method: "POST",
body: new URLSearchParams({ name: "My Feed" })
});
const responseText = await response.text();
const token = responseText.match(/(\w{20}).xml/)![1];
2020-03-18 20:33:10 +01:00
const feed = fs.readFileSync(feedPath(token)).toString();
expect(feed).toMatch("My Feed");
2020-03-18 20:21:44 +01:00
});
2020-03-19 01:16:00 +01:00
2020-03-19 01:58:41 +01:00
test("redirectServer", async () => {
const response = await fetch("http://localhost:8080/something?other", {
redirect: "manual"
});
expect(response.status).toBe(301);
expect(response.headers.get("Location")).toBe(
"https://www.kill-the-newsletter.com/something?other"
);
});
2020-03-19 01:16:00 +01:00
afterAll(() => {
webServer.close();
2020-03-19 01:58:41 +01:00
redirectServer.close();
2020-03-19 01:16:00 +01:00
});