diff --git a/README.md b/README.md index 1a3f28c..acc0587 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,14 @@

Kill the Newsletter!

Convert email newsletters into Atom feeds

Convert email newsletters into Atom feeds

-

Source.github/workflows/main.yml

+

+ +Source + + +.github/workflows/main.yml + +

# Running Locally diff --git a/src/index.tsx b/src/index.tsx index 113ee26..649e889 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -21,7 +21,7 @@ export const webServer = express() ) .post("/", (req, res) => { const name = req.body.name; - const identifier = newIdentifier(); + const identifier = createIdentifier(); fs.writeFileSync( feedPath(identifier), renderXML(Feed({ name, identifier })) @@ -224,7 +224,7 @@ function Entry({ }) { return { entry: { - id: urn(newIdentifier()), + id: urn(createIdentifier()), title, author: { name: author }, updated: now(), @@ -233,7 +233,7 @@ function Entry({ }; } -function newIdentifier(): string { +function createIdentifier(): string { return cryptoRandomString({ length: 20, characters: "1234567890qwertyuiopasdfghjklzxcvbnm" diff --git a/src/test.ts b/src/test.ts index dfacdb4..2bda9a9 100644 --- a/src/test.ts +++ b/src/test.ts @@ -6,25 +6,19 @@ import qs from "qs"; test("create feed", async () => { const identifier = await createFeed(); - expect(await readFeed(identifier)).toMatch("My Feed"); + expect(await getFeed(identifier)).toMatch("My Feed"); }); describe("receive email", () => { - const transporter = nodemailer.createTransport({ - host: "localhost", - port: 2525, - tls: { rejectUnauthorized: false } - }); - test("HTML content", async () => { const identifier = await createFeed(); - await transporter.sendMail({ + await emailClient.sendMail({ from: "publisher@example.com", to: `${identifier}@kill-the-newsletter.com`, subject: "New Message", html: "

HTML content

" }); - const feed = await readFeed(identifier); + const feed = await getFeed(identifier); expect(feed).toMatch("publisher@example.com"); expect(feed).toMatch("New Message"); expect(feed).toMatch("HTML content"); @@ -32,29 +26,29 @@ describe("receive email", () => { test("text content", async () => { const identifier = await createFeed(); - await transporter.sendMail({ + await emailClient.sendMail({ from: "publisher@example.com", to: `${identifier}@kill-the-newsletter.com`, subject: "New Message", text: "TEXT content" }); - const feed = await readFeed(identifier); + const feed = await getFeed(identifier); expect(feed).toMatch("TEXT content"); }); test("truncation", async () => { const identifier = await createFeed(); for (const repetition of [...new Array(4).keys()]) - await transporter.sendMail({ + await emailClient.sendMail({ from: "publisher@example.com", to: `${identifier}@kill-the-newsletter.com`, subject: "New Message", text: `REPETITION ${repetition} `.repeat(10_000) }); - const feed = await readFeed(identifier); + const feed = await getFeed(identifier); expect(feed).toMatch("REPETITION 3"); expect(feed).not.toMatch("REPETITION 0"); - }, 10_000); + }); }); afterAll(() => { @@ -63,10 +57,13 @@ afterAll(() => { emailServer.close(() => {}); }); +const webClient = axios.create({ baseURL: "http://localhost:8000" }); +const emailClient = nodemailer.createTransport("smtp://localhost:2525"); + async function createFeed(): Promise { return ( - await axios.post( - "http://localhost:8000", + await webClient.post( + "/", qs.stringify({ name: "My Feed" }) @@ -74,7 +71,6 @@ async function createFeed(): Promise { ).data.match(/(\w{20}).xml/)![1]; } -async function readFeed(identifier: string): Promise { - return (await axios.get(`http://localhost:8000/feeds/${identifier}.xml`)) - .data; +async function getFeed(identifier: string): Promise { + return (await webClient.get(`/feeds/${identifier}.xml`)).data; }