From 67662f21db7551a5df5f202a52b831183f036294 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Mon, 23 Mar 2020 11:08:57 -0400 Subject: [PATCH] . --- src/index.tsx | 13 ++++++++++--- src/test.ts | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index cd797a9..bb74f4c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -48,7 +48,9 @@ export const emailServer = new SMTPServer({ title: email.subject, author: email.from.text, // FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43234 / typeof email.html !== "boolean" => email.html !== false - content: typeof email.html !== "boolean" ? email.html : email.textAsHtml + ...(typeof email.html === "boolean" + ? { html: false, content: email.text ?? "" } + : { content: email.html }) }); for (const { address } of session.envelope.rcptTo) { const match = address.match(/^(\w+)@kill-the-newsletter.com$/); @@ -219,11 +221,13 @@ function Feed({ name, identifier }: { name: string; identifier: string }) { function Entry({ title, author, - content + content, + html }: { title: string; author: string; content: string; + html?: boolean; }) { return { entry: { @@ -231,7 +235,10 @@ function Entry({ title, author: { name: author }, updated: now(), - content: { $: { type: "html" }, _: content } + content: { + ...(html === false ? {} : { $: { type: "html" } }), + _: content + } } }; } diff --git a/src/test.ts b/src/test.ts index ca94fd8..34b84cf 100644 --- a/src/test.ts +++ b/src/test.ts @@ -36,6 +36,28 @@ describe("receive email", () => { expect(feed).toMatch("TEXT content"); }); + test("missing content", async () => { + const identifier = await createFeed(); + await emailClient.sendMail({ + from: "publisher@example.com", + to: `${identifier}@kill-the-newsletter.com`, + subject: "New Message" + }); + const feed = await getFeed(identifier); + expect(feed).toMatch("New Message"); + }); + + test("missing subject", async () => { + const identifier = await createFeed(); + await emailClient.sendMail({ + from: "publisher@example.com", + to: `${identifier}@kill-the-newsletter.com`, + html: "

HTML content

" + }); + const feed = await getFeed(identifier); + expect(feed).toMatch("HTML content"); + }); + test("truncation", async () => { const identifier = await createFeed(); for (const repetition of [...new Array(4).keys()])