This commit is contained in:
Leandro Facchinetti 2021-03-13 10:45:13 +00:00
parent accfadf188
commit 7298c7f63f
3 changed files with 36 additions and 19 deletions

View File

@ -6,9 +6,7 @@ module.exports = (require) => {
console.log(`Web server started at ${webApplication.get("url")}`); console.log(`Web server started at ${webApplication.get("url")}`);
}); });
emailApplication.listen(webApplication.get("email port"), () => { emailApplication.listen(new URL(webApplication.get("email")).port, () => {
console.log( console.log(`Email server started at port ${webApplication.get("email")}`);
`Email server started on port ${webApplication.get("email port")}`
);
}); });
}; };

View File

@ -1,8 +1,33 @@
import { webServer, emailServer, BASE_URL, EMAIL_DOMAIN, EMAIL_PORT } from "."; import { beforeAll, afterAll, describe, test, expect } from "@jest/globals";
import os from "os";
import path from "path";
import http from "http";
import net from "net";
import fs from "fs";
import * as got from "got";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import axios from "axios"; import killTheNewsletter from ".";
import qs from "qs";
import { JSDOM } from "jsdom"; let webServer: http.Server;
let emailServer: net.Server;
let webClient: got.Got;
let emailClient: nodemailer.Transporter;
beforeAll(() => {
const rootDirectory = fs.mkdtempSync(
path.join(os.tmpdir(), "kill-the-newsletter--test--")
);
const { webApplication, emailApplication } = killTheNewsletter(rootDirectory);
webServer = webApplication.listen(new URL(webApplication.get("url")).port);
emailServer = emailApplication.listen(
new URL(webApplication.get("email")).port
);
webClient = got.default.extend({ prefixUrl: webApplication.get("url") });
emailClient = nodemailer.createTransport(webApplication.get("email"));
});
afterAll(() => {
webServer.close();
emailServer.close();
});
test("create feed", async () => { test("create feed", async () => {
const identifier = await createFeed(); const identifier = await createFeed();
@ -235,12 +260,6 @@ test("noindex header", async () => {
); );
}); });
const webClient = axios.create({
baseURL: BASE_URL,
});
const emailClient = nodemailer.createTransport(
`smtp://${EMAIL_DOMAIN}:${EMAIL_PORT}`
);
afterAll(() => { afterAll(() => {
webServer.close(); webServer.close();
emailServer.close(); emailServer.close();

View File

@ -20,8 +20,7 @@ export default function killTheNewsletter(
const webApplication = express(); const webApplication = express();
webApplication.set("url", "http://localhost:4000"); webApplication.set("url", "http://localhost:4000");
webApplication.set("email port", 2525); webApplication.set("email", "smtp://localhost:2525");
webApplication.set("email host", "localhost");
webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com"); webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com");
fs.ensureDirSync(rootDirectory); fs.ensureDirSync(rootDirectory);
@ -287,7 +286,8 @@ export default function killTheNewsletter(
<p> <p>
Sign up for the newsletter with<br /> Sign up for the newsletter with<br />
<code class="copyable" <code class="copyable"
>${feedReference}@${webApplication.get("email host")}</code >${feedReference}@${new URL(webApplication.get("email"))
.hostname}</code
> >
</p> </p>
<p> <p>
@ -376,7 +376,7 @@ export default function killTheNewsletter(
<title>${feed.title}</title> <title>${feed.title}</title>
<subtitle <subtitle
>Kill the Newsletter! Inbox: >Kill the Newsletter! Inbox:
${feedReference}@${webApplication.get("email host")} ${feedReference}@${new URL(webApplication.get("email")).hostname}
${webApplication.get("url")}/feeds/${feedReference}.xml</subtitle ${webApplication.get("url")}/feeds/${feedReference}.xml</subtitle
> >
<updated>${new Date(feed.updatedAt).toISOString()}</updated> <updated>${new Date(feed.updatedAt).toISOString()}</updated>
@ -443,7 +443,7 @@ export default function killTheNewsletter(
disabledCommands: ["AUTH", "STARTTLS"], disabledCommands: ["AUTH", "STARTTLS"],
async onData(stream, session, callback) { async onData(stream, session, callback) {
try { try {
const atHost = "@" + webApplication.get("email host"); const atHost = "@" + new URL(webApplication.get("email")).hostname;
const email = await mailparser.simpleParser(stream); const email = await mailparser.simpleParser(stream);
const from = email.from?.text ?? ""; const from = email.from?.text ?? "";
const subject = email.subject ?? ""; const subject = email.subject ?? "";