diff --git a/src/index.tsx b/src/index.tsx index b479899..9f701ed 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -22,13 +22,14 @@ const webApp = express() ) ) .post("/", (req, res) => { - const inbox: Inbox = { name: req.body.name, token: newToken() }; - fs.writeFileSync(feedPath(inbox.token), renderXML(Feed(inbox))); + const name = req.body.name; + const token = newToken(); + fs.writeFileSync(feedPath(token), renderXML(Feed({ name, token }))); res.send( renderHTML(

“{name}” Inbox Created

- +
) ); @@ -103,11 +104,6 @@ if (process.env.NODE_ENV === "production") { developmentEmailServer.listen(2525); } -type Inbox = { - name: string; - token: string; -}; - function Layout({ children }: { children: React.ReactNode }) { return ( @@ -183,7 +179,7 @@ function Form() { ); } -function Created({ inbox: { name, token } }: { inbox: Inbox }) { +function Created({ token }: { token: string }) { return ( <>

@@ -213,8 +209,7 @@ function Created({ inbox: { name, token } }: { inbox: Inbox }) { ); } -function Feed(inbox: Inbox) { - const { name, token } = inbox; +function Feed({ name, token }: { name: string; token: string }) { return { feed: { $: { xmlns: "http://www.w3.org/2005/Atom" }, @@ -242,7 +237,7 @@ function Feed(inbox: Inbox) { title: `“${name}” Inbox Created`, author: "Kill the Newsletter!", content: ReactDOMServer.renderToStaticMarkup( - + ) }) } @@ -280,7 +275,7 @@ function now(): string { return new Date().toISOString(); } -export function feedPath(token: string): string { +function feedPath(token: string): string { return `static/feeds/${token}.xml`; } diff --git a/src/test.ts b/src/test.ts index babddd8..efb8041 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,18 +1,12 @@ -import { - developmentWebServer, - developmentEmailServer, - feedPath, - feedEmail -} from "."; +import { developmentWebServer, developmentEmailServer, feedEmail } from "."; import nodemailer from "nodemailer"; import axios from "axios"; import qs from "qs"; -import fs from "fs"; test("create feed", async () => { const token = await createFeed(); - expect(readFeed(token)).toMatch("My Feed"); + expect(await readFeed(token)).toMatch("My Feed"); }); describe("receive email", () => { @@ -30,7 +24,7 @@ describe("receive email", () => { subject: "New Message", html: "

HTML content

" }); - const feed = readFeed(token); + const feed = await readFeed(token); expect(feed).toMatch("publisher@example.com"); expect(feed).toMatch("New Message"); expect(feed).toMatch("HTML content"); @@ -44,7 +38,7 @@ describe("receive email", () => { subject: "New Message", text: "TEXT content" }); - const feed = readFeed(token); + const feed = await readFeed(token); expect(feed).toMatch("TEXT content"); }); @@ -57,7 +51,7 @@ describe("receive email", () => { subject: "New Message", text: `REPETITION ${repetition} `.repeat(10_000) }); - const feed = readFeed(token); + const feed = await readFeed(token); expect(feed).toMatch("REPETITION 3"); expect(feed).not.toMatch("REPETITION 0"); }, 10_000); @@ -80,6 +74,6 @@ async function createFeed(): Promise { ).data.match(/(\w{20}).xml/)![1]; } -function readFeed(token: string): string { - return fs.readFileSync(feedPath(token), "utf8"); +async function readFeed(token: string): Promise { + return (await axios.get(`http://localhost:8000/feeds/${token}.xml`)).data; }