This commit is contained in:
parent
792a592eda
commit
c72a764c93
|
@ -22,13 +22,14 @@ const webApp = express()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.post("/", (req, res) => {
|
.post("/", (req, res) => {
|
||||||
const inbox: Inbox = { name: req.body.name, token: newToken() };
|
const name = req.body.name;
|
||||||
fs.writeFileSync(feedPath(inbox.token), renderXML(Feed(inbox)));
|
const token = newToken();
|
||||||
|
fs.writeFileSync(feedPath(token), renderXML(Feed({ name, token })));
|
||||||
res.send(
|
res.send(
|
||||||
renderHTML(
|
renderHTML(
|
||||||
<Layout>
|
<Layout>
|
||||||
<h1>“{name}” Inbox Created</h1>
|
<h1>“{name}” Inbox Created</h1>
|
||||||
<Created inbox={inbox}></Created>
|
<Created token={token}></Created>
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -103,11 +104,6 @@ if (process.env.NODE_ENV === "production") {
|
||||||
developmentEmailServer.listen(2525);
|
developmentEmailServer.listen(2525);
|
||||||
}
|
}
|
||||||
|
|
||||||
type Inbox = {
|
|
||||||
name: string;
|
|
||||||
token: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
function Layout({ children }: { children: React.ReactNode }) {
|
function Layout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -183,7 +179,7 @@ function Form() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Created({ inbox: { name, token } }: { inbox: Inbox }) {
|
function Created({ token }: { token: string }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<p>
|
||||||
|
@ -213,8 +209,7 @@ function Created({ inbox: { name, token } }: { inbox: Inbox }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Feed(inbox: Inbox) {
|
function Feed({ name, token }: { name: string; token: string }) {
|
||||||
const { name, token } = inbox;
|
|
||||||
return {
|
return {
|
||||||
feed: {
|
feed: {
|
||||||
$: { xmlns: "http://www.w3.org/2005/Atom" },
|
$: { xmlns: "http://www.w3.org/2005/Atom" },
|
||||||
|
@ -242,7 +237,7 @@ function Feed(inbox: Inbox) {
|
||||||
title: `“${name}” Inbox Created`,
|
title: `“${name}” Inbox Created`,
|
||||||
author: "Kill the Newsletter!",
|
author: "Kill the Newsletter!",
|
||||||
content: ReactDOMServer.renderToStaticMarkup(
|
content: ReactDOMServer.renderToStaticMarkup(
|
||||||
<Created inbox={inbox}></Created>
|
<Created token={token}></Created>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -280,7 +275,7 @@ function now(): string {
|
||||||
return new Date().toISOString();
|
return new Date().toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function feedPath(token: string): string {
|
function feedPath(token: string): string {
|
||||||
return `static/feeds/${token}.xml`;
|
return `static/feeds/${token}.xml`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
src/test.ts
20
src/test.ts
|
@ -1,18 +1,12 @@
|
||||||
import {
|
import { developmentWebServer, developmentEmailServer, feedEmail } from ".";
|
||||||
developmentWebServer,
|
|
||||||
developmentEmailServer,
|
|
||||||
feedPath,
|
|
||||||
feedEmail
|
|
||||||
} from ".";
|
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import fs from "fs";
|
|
||||||
|
|
||||||
test("create feed", async () => {
|
test("create feed", async () => {
|
||||||
const token = await createFeed();
|
const token = await createFeed();
|
||||||
|
|
||||||
expect(readFeed(token)).toMatch("My Feed");
|
expect(await readFeed(token)).toMatch("My Feed");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("receive email", () => {
|
describe("receive email", () => {
|
||||||
|
@ -30,7 +24,7 @@ describe("receive email", () => {
|
||||||
subject: "New Message",
|
subject: "New Message",
|
||||||
html: "<p>HTML content</p>"
|
html: "<p>HTML content</p>"
|
||||||
});
|
});
|
||||||
const feed = readFeed(token);
|
const feed = await readFeed(token);
|
||||||
expect(feed).toMatch("publisher@example.com");
|
expect(feed).toMatch("publisher@example.com");
|
||||||
expect(feed).toMatch("New Message");
|
expect(feed).toMatch("New Message");
|
||||||
expect(feed).toMatch("HTML content");
|
expect(feed).toMatch("HTML content");
|
||||||
|
@ -44,7 +38,7 @@ describe("receive email", () => {
|
||||||
subject: "New Message",
|
subject: "New Message",
|
||||||
text: "TEXT content"
|
text: "TEXT content"
|
||||||
});
|
});
|
||||||
const feed = readFeed(token);
|
const feed = await readFeed(token);
|
||||||
expect(feed).toMatch("TEXT content");
|
expect(feed).toMatch("TEXT content");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,7 +51,7 @@ describe("receive email", () => {
|
||||||
subject: "New Message",
|
subject: "New Message",
|
||||||
text: `REPETITION ${repetition} `.repeat(10_000)
|
text: `REPETITION ${repetition} `.repeat(10_000)
|
||||||
});
|
});
|
||||||
const feed = readFeed(token);
|
const feed = await readFeed(token);
|
||||||
expect(feed).toMatch("REPETITION 3");
|
expect(feed).toMatch("REPETITION 3");
|
||||||
expect(feed).not.toMatch("REPETITION 0");
|
expect(feed).not.toMatch("REPETITION 0");
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
|
@ -80,6 +74,6 @@ async function createFeed(): Promise<string> {
|
||||||
).data.match(/(\w{20}).xml/)![1];
|
).data.match(/(\w{20}).xml/)![1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function readFeed(token: string): string {
|
async function readFeed(token: string): Promise<string> {
|
||||||
return fs.readFileSync(feedPath(token), "utf8");
|
return (await axios.get(`http://localhost:8000/feeds/${token}.xml`)).data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue