kill-the-newsletter/src/test.ts

21 lines
575 B
TypeScript
Raw Normal View History

2020-03-19 03:41:40 +01:00
import { developmentWebServer, emailServer, 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 02:44:21 +01:00
test("create feed", async () => {
const response = await fetch("http://localhost:8000", {
2020-03-19 01:16:00 +01:00
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
afterAll(() => {
2020-03-19 02:44:21 +01:00
developmentWebServer.close();
2020-03-19 03:41:40 +01:00
emailServer.close(() => {});
2020-03-19 01:16:00 +01:00
});