diff --git a/src/index.test.ts b/src/index.test.ts index b472f84..e19b777 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -4,10 +4,10 @@ You may send emails manually from the command line with the following: cat << "EOF" > /tmp/example-email.txt From: Publisher To: ru9rmeebswmcy7wx@localhost -Subject: A subject +Subject: Test email with HTML Date: Sat, 13 Mar 2021 11:30:40 -

Some HTML content

+

Some HTML

EOF curl smtp://localhost:2525 --mail-from publisher@example.com --mail-rcpt ru9rmeebswmcy7wx@localhost --upload-file /tmp/example-email.txt @@ -68,8 +68,8 @@ test("Kill the Newsletter!", async () => { await emailClient.sendMail({ from: "publisher@example.com", to: `${feedReference}@${emailHost}`, - subject: "A subject", - html: html`

Some HTML content

`, + subject: "Test email with HTML", + html: html`

Some HTML

`, }); let feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; expect(feed.match(/(.+?)<\/updated>/)![1]).not.toBe( @@ -78,10 +78,35 @@ test("Kill the Newsletter!", async () => { expect(feed).toMatch( html`publisher@example.com` ); - expect(feed).toMatch(html`A subject`); + expect(feed).toMatch(html`Test email with HTML`); expect(feed).toMatch( // prettier-ignore - html`${`

Some HTML content

`}\n
` + html`${`

Some HTML

`}\n
` + ); + + // Test email with plain text + await emailClient.sendMail({ + from: "publisher@example.com", + to: `${feedReference}@${emailHost}`, + subject: "Test email with plain text", + text: "Some plain text", + }); + feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; + expect(feed).toMatch( + html`${`

Some plain text

`}
` + ); + + // Test email with rich text + await emailClient.sendMail({ + from: "publisher@example.com", + to: `${feedReference}@${emailHost}`, + subject: "Test email with rich text", + text: "A link: https://kill-the-newsletter.com", + }); + feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; + expect(feed).toMatch( + // prettier-ignore + html`${`

A link: https://kill-the-newsletter.com

`}
` ); // Stop servers @@ -91,41 +116,6 @@ test("Kill the Newsletter!", async () => { /* describe("receive email", () => { - test("text content", async () => { - const identifier = await createFeed(); - await emailClient.sendMail({ - from: "publisher@example.com", - to: `${identifier}@${EMAIL_DOMAIN}`, - subject: "New Message", - text: "TEXT content", - }); - const feed = await getFeed(identifier); - const entry = feed.querySelector("feed > entry:first-of-type")!; - const alternate = await getAlternate( - entry.querySelector("link")!.getAttribute("href")! - ); - expect(entry.querySelector("content")!.textContent).toMatch("TEXT content"); - expect(alternate.querySelector("p")!.textContent).toMatch("TEXT content"); - }); - - test("rich text content", async () => { - const identifier = await createFeed(); - await emailClient.sendMail({ - from: "publisher@example.com", - to: `${identifier}@${EMAIL_DOMAIN}`, - subject: "New Message", - text: "TEXT content\n\nhttps://leafac.com\n\nMore text", - }); - const feed = await getFeed(identifier); - const entry = feed.querySelector("feed > entry:first-of-type")!; - const alternate = await getAlternate( - entry.querySelector("link")!.getAttribute("href")! - ); - expect(alternate.querySelector("a")!.getAttribute("href")).toBe( - "https://leafac.com" - ); - }); - test("invalid XML character in HTML", async () => { const identifier = await createFeed(); await emailClient.sendMail({ diff --git a/src/index.ts b/src/index.ts index 41b78fe..129bc10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -356,7 +356,7 @@ export default function killTheNewsletter( SELECT "createdAt", "reference", "title", "author", "content" FROM "entries" WHERE "feed" = ${feed.id} - ORDER BY "createdAt" DESC + ORDER BY "id" DESC ` ); @@ -479,7 +479,7 @@ export default function killTheNewsletter( ); while (renderFeed(feedReference)!.length > 500_000) database.run( - sql`DELETE FROM "entries" WHERE "feed" = ${feed.id} ORDER BY "createdAt" ASC LIMIT 1` + sql`DELETE FROM "entries" WHERE "feed" = ${feed.id} ORDER BY "id" ASC LIMIT 1` ); } });