Use maildev for catching and parsing verification emails in e2e tests

This commit is contained in:
Martin Kleinschrodt 2022-02-18 12:28:36 +01:00
parent cb26c6fce2
commit c4e67381ee
6 changed files with 2135 additions and 114 deletions

View File

@ -18,7 +18,7 @@ Cypress.Commands.add("signup", () => {
cy.visit("/");
const { email, emailToken, password, name } = Cypress.env();
const { email, password, name } = Cypress.env();
cy.get("pl-app").find("pl-start").find("pl-login-signup").find("pl-input#emailInput").find("input").type(email);
@ -28,14 +28,21 @@ Cypress.Commands.add("signup", () => {
.find("pl-button#submitEmailButton")
.click({ force: true });
// Give the app some time to finish animations
cy.wait(100);
// Give the app some time to finish animations and email to arrive
cy.wait(2000);
cy.get("pl-app")
.find("pl-prompt-dialog")
.find("pl-input")
.find("input[placeholder='Enter Verification Code']")
.type(emailToken, { force: true });
cy.request("http://localhost:1080/email").should((res) => {
const latest = res.body.sort((a, b) => (a.time > b.time ? -1 : 1))[0];
expect(latest).to.not.be.undefined;
const matchCode = latest.text.match(/(\d{6})/);
const emailToken = matchCode && matchCode[1];
expect(emailToken).to.not.be.null;
cy.get("pl-app")
.find("pl-prompt-dialog")
.find("pl-input")
.find("input[placeholder='Enter Verification Code']")
.type(emailToken, { force: true });
});
// Give the app some time to finish animations
cy.wait(100);
@ -157,7 +164,7 @@ Cypress.Commands.add("login", () => {
cy.visit("/");
const { email, emailToken, password } = Cypress.env();
const { email, password } = Cypress.env();
cy.get("pl-app").find("pl-start").find("pl-login-signup").find("pl-input#emailInput").find("input").type(email);
@ -167,14 +174,21 @@ Cypress.Commands.add("login", () => {
.find("pl-button#submitEmailButton")
.click({ force: true });
// Give the app some time to render the animations
cy.wait(100);
// Give the app some time to finish animations and email to arrive
cy.wait(2000);
cy.get("pl-app")
.find("pl-prompt-dialog")
.find("pl-input")
.find("input[placeholder='Enter Verification Code']")
.type(emailToken, { force: true });
cy.request("http://localhost:1080/email").should((res) => {
const latest = res.body.sort((a, b) => (a.time > b.time ? -1 : 1))[0];
expect(latest).to.not.be.undefined;
const matchCode = latest.text.match(/(\d{6})/);
const emailToken = matchCode && matchCode[1];
expect(emailToken).to.not.be.null;
cy.get("pl-app")
.find("pl-prompt-dialog")
.find("pl-input")
.find("input[placeholder='Enter Verification Code']")
.type(emailToken, { force: true });
});
cy.get("pl-app").find("pl-prompt-dialog").find("pl-button#confirmButton").click({ force: true });
@ -252,7 +266,7 @@ Cypress.Commands.add("v3_signup", () => {
cy.clearLocalStorage();
cy.clearIndexedDb();
const { v3_email, emailToken, password, v3_url, name } = Cypress.env();
const { v3_email, password, v3_url, name } = Cypress.env();
cy.visit(`${v3_url}/`);
@ -281,15 +295,21 @@ Cypress.Commands.add("v3_signup", () => {
.find("pl-loading-button#submitEmailButton")
.click({ force: true });
// Give the app some time to finish animations
cy.wait(100);
// Give the app some time to finish animations and email to arrive
cy.wait(2000);
cy.get("pl-app")
.find("pl-start")
.find("pl-signup")
.find("pl-input#codeInput")
.find("input")
.type(emailToken, { force: true });
cy.request("http://localhost:1080/email").should((res) => {
const latest = res.body.sort((a, b) => (a.time > b.time ? -1 : 1))[0];
expect(latest).to.not.be.undefined;
const matchCode = latest.text.match(/(\d{6})/);
const emailToken = matchCode && matchCode[1];
expect(emailToken).to.not.be.null;
cy.get("pl-app")
.find("pl-prompt-dialog")
.find("pl-input")
.find("input[placeholder='Enter Verification Code']")
.type(emailToken, { force: true });
});
cy.get("pl-app")
.find("pl-start")

2161
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@
"cypress": "9.3.1",
"http-server": "14.1.0",
"lerna": "4.0.0",
"maildev": "1.1.0",
"prettier": "2.5.1",
"ts-node": "10.0.0",
"typescript": "4.4.3",
@ -50,8 +51,8 @@
"tauri:build:production": "lerna run build:production",
"repl": "cd packages/server && npm run repl && cd ../..",
"test": "lerna run test",
"test:e2e": "concurrently --prefix=name --prefix-length=30 --kill-others --success=first -n app,v3-app,cypress \"PL_DATA_BACKEND=memory PL_E2E_TESTS=true PL_DISABLE_SW=true npm start\" \"npm run start:v3\" \"./node_modules/.bin/wait-on tcp:localhost:8080 && CYPRESS_CRASH_REPORTS=0 cypress run\"",
"test:e2e:dev": "concurrently --prefix=name --prefix-length=30 --kill-others --success=first -n app,v3-app,cypress \"PL_DATA_BACKEND=memory PL_E2E_TESTS=true PL_DISABLE_SW=true npm run dev\" \"npm run start:v3\" \"./node_modules/.bin/wait-on tcp:localhost:8080 && CYPRESS_CRASH_REPORTS=0 cypress open\"",
"test:e2e": "concurrently --prefix=name --prefix-length=30 --kill-others --success=first -n app,v3-app,cypress \"PL_DATA_BACKEND=memory PL_DISABLE_SW=true PL_EMAIL_BACKEND=smtp PL_EMAIL_SMTP_IGNORE_TLS=true npm start\" \"npm run start:v3\" \"npx maildev\" \"./node_modules/.bin/wait-on tcp:localhost:8080 && CYPRESS_CRASH_REPORTS=0 cypress run\"",
"test:e2e:dev": "concurrently --prefix=name --prefix-length=30 --kill-others --success=first -n app,v3-app,cypress \"PL_DATA_BACKEND=memory PL_DISABLE_SW=true PL_EMAIL_BACKEND=smtp PL_EMAIL_SMTP_IGNORE_TLS=true npm run dev\" \"npm run start:v3\" \"npx maildev\" \"./node_modules/.bin/wait-on tcp:localhost:8080 && CYPRESS_CRASH_REPORTS=0 cypress open\"",
"locale:extract": "lerna run extract --scope '@padloc/locale'",
"add": "lerna add $1 --scope=@padloc/$scope",
"remove": "rm packages/$scope/package-lock.json && lerna exec \"npm uninstall $1\" --scope=@padloc/$scope",

View File

@ -62,7 +62,6 @@ module.exports = {
PL_DISABLE_SW: true,
PL_AUTH_DEFAULT_TYPE: null,
PL_APP_NAME: name,
PL_E2E_TESTS: false,
PL_TERMS_OF_SERVICE: terms_of_service,
}),
new CleanWebpackPlugin(),

View File

@ -15,10 +15,6 @@ export class EmailAuthServer implements AuthServer {
authenticator.state = { email };
if (authenticator.status !== AuthenticatorStatus.Active) {
authenticator.state.activationCode = await this._generateCode();
// Override token if running e2e tests
if (process.env.PL_E2E_TESTS && process.env.PL_E2E_TESTS === "true" && email.endsWith("@example.com")) {
authenticator.state.activationCode = "000000";
}
const requestId = authenticator.id.split("-")[0];
const sentAt = new Date().toISOString();
try {
@ -48,10 +44,6 @@ export class EmailAuthServer implements AuthServer {
async initAuthRequest(authenticator: Authenticator, request: AuthRequest) {
let verificationCode = await this._generateCode();
const email = authenticator.state.email;
// Override token if running e2e tests
if (process.env.PL_E2E_TESTS && process.env.PL_E2E_TESTS === "true" && email.endsWith("@example.com")) {
verificationCode = "000000";
}
request.state = {
email,
verificationCode,

View File

@ -20,6 +20,9 @@ export class SMTPConfig extends Config {
@ConfigParam("boolean")
secure: boolean = false;
@ConfigParam("boolean")
ignoreTLS: boolean = false;
@ConfigParam()
user: string = "";
@ -50,6 +53,7 @@ export class SMTPSender implements Messenger {
port: config.port,
secure: config.secure,
auth: auth,
ignoreTLS: config.ignoreTLS,
} as TransportOptions);
this._loadTemplates(this.config.templateDir);