Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

📦️ Update smtp-tester and fix test environment config (#1181)

Luke Vellaf66653c21abc
diff --git a/apps/web/.env.test b/apps/web/.env.test
index c826ce18b..1364428fe 100644
--- a/apps/web/.env.test
+++ b/apps/web/.env.test
@@ -4,4 +4,5 @@ NEXTAUTH_URL=$NEXT_PUBLIC_BASE_URL
SECRET_PASSWORD=abcdef1234567890abcdef1234567890
DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly
+SMTP_HOST=localhost
SMTP_PORT=4025
\ No newline at end of file
diff --git a/apps/web/declarations/smpt-tester.d.ts b/apps/web/declarations/smpt-tester.d.ts
deleted file mode 100644
index 2b5254b21..000000000
--- a/apps/web/declarations/smpt-tester.d.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-declare module "smtp-tester" {
- /**
- * Initializes the SMTP tester.
- *
- * @param port The port of the SMTP server.
- */
- function init(port: number): SmtpTester;
-
- /**
- * A callback that occurs when an email is received.
- *
- * @param recipient The bound recipient. Can be `undefined` if the handler is not bound to a specific recipient.
- * @param id The local incrementing identifier of the email.
- * @param email The email being received.
- */
- type OnReceiveEmail = (
- recipient: string,
- id: number,
- email: EmailInfo,
- ) => void;
-
- type CaptureOneResponse = {
- address: string;
- id: string;
- email: EmailInfo;
- };
- /**
- * The SMTP tester.
- */
- interface SmtpTester {
- /**
- * Binds a callback to a specific recipient that is fired whenever an email is received for that specific recipient.
- *
- * @param recipient The recipient to bind to.
- * @param callback The callback function.
- */
- bind(recipient: string, callback: OnReceiveEmail): void;
-
- /**
- * Binds a callback that is fired whenever an email is received.
- *
- * @param callback The callback function.
- */
- bind(callback: OnReceiveEmail): void;
-
- /**
- * Captures the next email received by the server.
- *
- * @param recipient The recipient to capture for. If not specified, the next email received will be captured.
- * @param options The options for the capture.
- */
- captureOne(
- recipient: string,
- options?: CaptureOptions,
- ): Promise<CaptureOneResponse>;
-
- /**
- * Stops the running SMTP server.
- */
- stop(): void;
-
- /**
- * Stops the running SMTP server.
- *
- * @param callback The callback that is fired when the server has stopped.
- */
- stop(callback: () => void): void;
- }
-
- /**
- * Contains information about a received email.
- */
- interface EmailInfo {
- /**
- * The sender of the email.
- */
- readonly sender: string;
-
- /**
- * The body of the email.
- */
- readonly body: string;
-
- /**
- * The HTML body of the email.
- */
- readonly html: string;
-
- /**
- * Headers of the email.
- */
- readonly headers: {
- /**
- * Who the email was sent from.
- */
- from: string;
-
- /**
- * Who the email was sent to.
- */
- to: string;
-
- /**
- * The subject of the email.
- */
- subject: string;
-
- [string]: string;
- };
- }
-}
diff --git a/apps/web/package.json b/apps/web/package.json
index f6f8677c9..444154272 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -92,7 +92,7 @@
"vitest": "^1.3.1",
"i18next-scanner": "^4.2.0",
"i18next-scanner-typescript": "^1.1.1",
- "smtp-tester": "^2.0.1",
+ "smtp-tester": "^2.1.0",
"wait-on": "^6.0.1"
}
}
diff --git a/apps/web/tests/authentication.spec.ts b/apps/web/tests/authentication.spec.ts
index 4ba110d35..59005d313 100644
--- a/apps/web/tests/authentication.spec.ts
+++ b/apps/web/tests/authentication.spec.ts
@@ -4,7 +4,7 @@ import { load } from "cheerio";
import smtpTester from "smtp-tester";
const testUserEmail = "[email protected]";
-let mailServer: smtpTester.SmtpTester;
+let mailServer: smtpTester.MailServer;
/**
* Get the 6-digit code from the email
* @returns 6-digit code
@@ -14,6 +14,10 @@ const getCode = async () => {
wait: 5000,
});
+ if (!email.html) {
+ throw new Error("Email doesn't contain HTML");
+ }
+
const $ = load(email.html);
return $("#code").text().trim();
@@ -34,7 +38,8 @@ test.describe.serial(() => {
} catch {
// User doesn't exist
}
- mailServer.stop();
+
+ mailServer.stop(() => {});
});
test.describe("new user", () => {
@@ -109,6 +114,10 @@ test.describe.serial(() => {
wait: 5000,
});
+ if (!email.html) {
+ throw new Error("Email doesn't contain HTML");
+ }
+
const $ = load(email.html);
const magicLink = $("#magicLink").attr("href");
diff --git a/apps/web/tests/create-delete-poll.spec.ts b/apps/web/tests/create-delete-poll.spec.ts
index 0b7cf386e..e2081c558 100644
--- a/apps/web/tests/create-delete-poll.spec.ts
+++ b/apps/web/tests/create-delete-poll.spec.ts
@@ -1,18 +1,18 @@
import { expect, Page, test } from "@playwright/test";
-import smtpTester, { SmtpTester } from "smtp-tester";
+import smtpTester, { MailServer } from "smtp-tester";
import { NewPollPage } from "tests/new-poll-page";
test.describe.serial(() => {
let page: Page;
- let mailServer: SmtpTester;
+ let mailServer: MailServer;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
mailServer = smtpTester.init(4025);
});
test.afterAll(async () => {
- mailServer.stop();
+ mailServer.stop(() => {});
});
test("create a new poll", async () => {
diff --git a/apps/web/tests/edit-options.spec.ts b/apps/web/tests/edit-options.spec.ts
index 451af7abe..37847fd6b 100644
--- a/apps/web/tests/edit-options.spec.ts
+++ b/apps/web/tests/edit-options.spec.ts
@@ -1,12 +1,12 @@
import { expect, Page, test } from "@playwright/test";
-import smtpTester, { SmtpTester } from "smtp-tester";
+import smtpTester, { MailServer } from "smtp-tester";
import { EditOptionsPage } from "tests/edit-options-page";
import { NewPollPage } from "tests/new-poll-page";
test.describe("edit options", () => {
let page: Page;
let editOptionsPage: EditOptionsPage;
- let mailServer: SmtpTester;
+ let mailServer: MailServer;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
@@ -19,7 +19,7 @@ test.describe("edit options", () => {
});
test.afterAll(async () => {
- mailServer.stop();
+ mailServer.stop(() => {});
});
test("should show warning when deleting options with votes in them", async () => {
diff --git a/apps/web/tests/vote-and-comment.spec.ts b/apps/web/tests/vote-and-comment.spec.ts
index 8908e8c26..9755e676b 100644
--- a/apps/web/tests/vote-and-comment.spec.ts
+++ b/apps/web/tests/vote-and-comment.spec.ts
@@ -1,6 +1,6 @@
import { expect, Page, Request, test } from "@playwright/test";
import { load } from "cheerio";
-import smtpTester, { SmtpTester } from "smtp-tester";
+import smtpTester, { MailServer } from "smtp-tester";
import { PollPage } from "tests/poll-page";
import { NewPollPage } from "./new-poll-page";
@@ -11,7 +11,7 @@ test.describe(() => {
let touchRequest: Promise<Request>;
let editSubmissionUrl: string;
- let mailServer: SmtpTester;
+ let mailServer: MailServer;
test.beforeAll(async ({ browser }) => {
mailServer = smtpTester.init(4025);
page = await browser.newPage();
@@ -26,7 +26,7 @@ test.describe(() => {
});
test.afterAll(async () => {
- mailServer.stop();
+ mailServer.stop(() => {});
});
test("should call touch endpoint", async () => {
@@ -62,7 +62,7 @@ test.describe(() => {
"Thanks for responding to Monthly Meetup",
);
- const $ = load(email.html);
+ const $ = load(email.html as string);
const href = $("#editSubmissionUrl").attr("href");
if (!href) {
diff --git a/yarn.lock b/yarn.lock
index b104631f1..bc8fab197 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5060,6 +5060,14 @@
"@types/node" "*"
iconv-lite "^0.6.3"
+"@types/mailparser@^3.4.0":
+ version "3.4.4"
+ resolved "https://registry.yarnpkg.com/@types/mailparser/-/mailparser-3.4.4.tgz#0bd71e205573b9dd9a445e10a8b8cb0e45420998"
+ integrity sha512-C6Znp2QVS25JqtuPyxj38Qh+QoFcLycdxsvcc6IZCGekhaMBzbdTXzwGzhGoYb3TfKu8IRCNV0sV1o3Od97cEQ==
+ dependencies:
+ "@types/node" "*"
+ iconv-lite "^0.6.3"
+
"@types/mdast@^3.0.0":
version "3.0.11"
resolved "https://registry.npmjs.org/@types/mdast/-/mdast-3.0.11.tgz"
@@ -5270,6 +5278,14 @@
resolved "https://registry.npmjs.org/@types/smoothscroll-polyfill/-/smoothscroll-polyfill-0.3.1.tgz"
integrity sha512-+KkHw4y+EyeCtVXET7woHUhIbfWFCflc0E0mZnSV+ZdjPQeHt/9KPEuT7gSW/kFQ8O3EG30PLO++YhChDt8+Ag==
+"@types/smtp-server@^3.5.7":
+ version "3.5.10"
+ resolved "https://registry.yarnpkg.com/@types/smtp-server/-/smtp-server-3.5.10.tgz#06d0338aea519469529847a12b0903678fdd6bea"
+ integrity sha512-i3Jx7sJ2qF52vjaOf3HguulXlWRFf6BSfsRLsIdmytDyVGv7KkhSs+gR9BXJnJWg1Ljkh/56Fh1Xqwa6u6X7zw==
+ dependencies:
+ "@types/node" "*"
+ "@types/nodemailer" "*"
+
"@types/unist@*", "@types/unist@^2.0.0":
version "2.0.6"
resolved "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz"
@@ -12335,11 +12351,13 @@ smtp-server@^3.11.0:
ipv6-normalize "1.0.1"
nodemailer "6.7.3"
-smtp-tester@^2.0.1:
- version "2.0.1"
- resolved "https://registry.npmjs.org/smtp-tester/-/smtp-tester-2.0.1.tgz"
- integrity sha512-mJicx4trPmlS2PY/ELG4LIKi8JdOGxnvm0/4oQxXErjwBT/crBUlyiMVzeliu69HHWeWRSOdTcNtlc34+1LodA==
+smtp-tester@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/smtp-tester/-/smtp-tester-2.1.0.tgz#ed67ef933767cacb8defcbf0683f29d75335a1ca"
+ integrity sha512-HfOBdHkdwoBO+Qb06H8ShVEc08nnvDbtYWzdT5iQMIeInBdLKu17XOhuaC79uM24zPApRfN3JAg627TIy3y/Ww==
dependencies:
+ "@types/mailparser" "^3.4.0"
+ "@types/smtp-server" "^3.5.7"
mailparser "^3.5.0"
smtp-server "^3.11.0"