From 1ed63f27ad649430a85e1b33e5bbf53c524dd39e Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Sun, 14 Mar 2021 23:09:27 +0000 Subject: [PATCH] --- src/index.test.ts | 59 ++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 1679321..34b97a7 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -23,7 +23,7 @@ test("Kill the Newsletter!", async () => { prefixUrl: webApplication.get("url"), }); const emailClient = nodemailer.createTransport(webApplication.get("email")); - const emailHost = new URL(webApplication.get("url")).hostname; + const emailHostname = new URL(webApplication.get("url")).hostname; // Create feed const create = (await webClient.post("", { form: { name: "A newsletter" } })) @@ -52,19 +52,20 @@ test("Kill the Newsletter!", async () => { await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for a second to test that the ‘’ field will be updated await emailClient.sendMail({ from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, + to: `${feedReference}@${emailHostname}`, subject: "Test email with HTML", html: html`

Some HTML

`, }); - const feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; - expect(feed.match(/(.+?)<\/updated>/)![1]).not.toBe( + const feedWithHTMLEntry = (await webClient.get(`feeds/${feedReference}.xml`)) + .body; + expect(feedWithHTMLEntry.match(/(.+?)<\/updated>/)![1]).not.toBe( feedOriginal.body.match(/(.+?)<\/updated>/)![1] ); - expect(feed).toMatch( + expect(feedWithHTMLEntry).toMatch( html`publisher@example.com` ); - expect(feed).toMatch(html`Test email with HTML`); - expect(feed).toMatch( + expect(feedWithHTMLEntry).toMatch(html`Test email with HTML`); + expect(feedWithHTMLEntry).toMatch( // prettier-ignore html`${`

Some HTML

`}\n
` ); @@ -72,7 +73,7 @@ test("Kill the Newsletter!", async () => { // Test email with text await emailClient.sendMail({ from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, + to: `${feedReference}@${emailHostname}`, subject: "Test email with text", text: "A link: https://kill-the-newsletter.com", }); @@ -81,20 +82,20 @@ test("Kill the Newsletter!", async () => { html`${`

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

`}
` ); - // Test email missing ‘from’ + // Test email missing fields await emailClient.sendMail({ - to: `${feedReference}@${emailHost}`, - subject: "Test email missing ‘from’", - text: "A link: https://kill-the-newsletter.com", + to: `${feedReference}@${emailHostname}`, }); - expect((await webClient.get(`feeds/${feedReference}.xml`)).body).toMatch( - html`` - ); + const feedMissingFields = (await webClient.get(`feeds/${feedReference}.xml`)) + .body; + expect(feedMissingFields).toMatch(html``); + expect(feedMissingFields).toMatch(html``); + expect(feedMissingFields).toMatch(html``); // Test email to nonexistent ‘to’ (gets ignored) await emailClient.sendMail({ from: "publisher@example.com", - to: `nonexistent@${emailHost}`, + to: `nonexistent@${emailHostname}`, subject: "Test email to nonexistent ‘to’ (gets ignored)", text: "A link: https://kill-the-newsletter.com", }); @@ -102,31 +103,11 @@ test("Kill the Newsletter!", async () => { "Test email to nonexistent ‘to’ (gets ignored)" ); - // Test email missing ‘subject’ - await emailClient.sendMail({ - from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, - text: "A link: https://kill-the-newsletter.com", - }); - expect((await webClient.get(`feeds/${feedReference}.xml`)).body).toMatch( - html`` - ); - - // Test email missing content - await emailClient.sendMail({ - from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, - subject: "Test email missing content", - }); - expect((await webClient.get(`feeds/${feedReference}.xml`)).body).toMatch( - html`` - ); - // Test truncation for (let index = 1; index <= 5; index++) await emailClient.sendMail({ from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, + to: `${feedReference}@${emailHostname}`, subject: `Test truncation: ${index}`, text: `TRUNCATION ${index} `.repeat(10_000), }); @@ -138,7 +119,7 @@ test("Kill the Newsletter!", async () => { // Test email that’s too long await emailClient.sendMail({ from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, + to: `${feedReference}@${emailHostname}`, subject: "Test email that’s too long", text: `TOO LONG `.repeat(100_000), }); @@ -151,7 +132,7 @@ test("Kill the Newsletter!", async () => { // Test email after truncation await emailClient.sendMail({ from: "publisher@example.com", - to: `${feedReference}@${emailHost}`, + to: `${feedReference}@${emailHostname}`, subject: "Test email after truncation", text: "A link: https://kill-the-newsletter.com", });