diff --git a/frontend/test/__support__/e2e/cypress.js b/frontend/test/__support__/e2e/cypress.js index c0b3f2c43725d221f01789f73488ccabea49569c..480bfa1ac91b63e60ddad7d14c9bf6d578ff6728 100644 --- a/frontend/test/__support__/e2e/cypress.js +++ b/frontend/test/__support__/e2e/cypress.js @@ -22,5 +22,6 @@ export * from "./helpers/e2e-cloud-helpers"; export * from "./helpers/e2e-data-model-helpers"; export * from "./helpers/e2e-misc-helpers"; export * from "./helpers/e2e-deprecated-helpers"; +export * from "./helpers/e2e-email-helpers"; Cypress.on("uncaught:exception", (err, runnable) => false); diff --git a/frontend/test/__support__/e2e/helpers/e2e-deprecated-helpers.js b/frontend/test/__support__/e2e/helpers/e2e-deprecated-helpers.js index 335ce2ef7f673f574afad3436f8612af8158c984..6025e28ddc76e590d079803630cf22e03eb9f7e5 100644 --- a/frontend/test/__support__/e2e/helpers/e2e-deprecated-helpers.js +++ b/frontend/test/__support__/e2e/helpers/e2e-deprecated-helpers.js @@ -17,18 +17,6 @@ export function createBasicAlert({ firstAlert, includeNormal } = {}) { cy.findByText("Let's set up your alert").should("not.exist"); } -export function setupDummySMTP() { - cy.log("Set up dummy SMTP server"); - cy.request("PUT", "/api/setting", { - "email-smtp-host": "smtp.foo.test", - "email-smtp-port": "587", - "email-smtp-security": "none", - "email-smtp-username": "nevermind", - "email-smtp-password": "it-is-secret-NOT", - "email-from-address": "nonexisting@metabase.test", - }); -} - export function createNativeQuestion(name, query) { return cy.request("POST", "/api/card", { name, diff --git a/frontend/test/__support__/e2e/helpers/e2e-email-helpers.js b/frontend/test/__support__/e2e/helpers/e2e-email-helpers.js new file mode 100644 index 0000000000000000000000000000000000000000..04506f424ea360200d40d1347e1de0a279e16599 --- /dev/null +++ b/frontend/test/__support__/e2e/helpers/e2e-email-helpers.js @@ -0,0 +1,28 @@ +/** + * Make sure you have webmail Docker image running locally: + * `docker run -p 80:80 -p 25:25 maildev/maildev` + * + * or + * + * install: `yarn global add maildev` + * run: `maildev -s 25 -w 80` + */ +export function setupSMTP() { + cy.log("Set up Webmail SMTP server"); + + cy.request("PUT", "/api/email", { + "email-smtp-host": "localhost", + "email-smtp-port": "25", + "email-smtp-username": "admin", + "email-smtp-password": "admin", + "email-smtp-security": "none", + "email-from-address": "mailer@metabase.test", + }); + + // We must always clear Webmail's inbox before each test + clearInbox(); +} + +export function clearInbox() { + cy.request("DELETE", "http://localhost:80/email/all"); +} diff --git a/frontend/test/metabase/scenarios/admin/people/people.cy.spec.js b/frontend/test/metabase/scenarios/admin/people/people.cy.spec.js index 478fd530ab94f2dae9f11c8a0bb79cd9991ab46b..4ade9cc5fe64919750e2ed7570bbfb82a2d7fa7c 100644 --- a/frontend/test/metabase/scenarios/admin/people/people.cy.spec.js +++ b/frontend/test/metabase/scenarios/admin/people/people.cy.spec.js @@ -3,7 +3,7 @@ import { restore, modal, popover, - setupDummySMTP, + setupSMTP, describeWithToken, } from "__support__/e2e/cypress"; import { USERS, USER_GROUPS } from "__support__/e2e/cypress_data"; @@ -182,7 +182,7 @@ describe("scenarios > admin > people", () => { const { first_name, last_name } = normal; const FULL_NAME = `${first_name} ${last_name}`; - setupDummySMTP(); + setupSMTP(); cy.visit("/admin/people"); showUserOptions(FULL_NAME); diff --git a/frontend/test/metabase/scenarios/admin/settings/email.cy.spec.js b/frontend/test/metabase/scenarios/admin/settings/email.cy.spec.js index c468cd01f5bdee366f21af96e596a5b90b68f6a6..c06d77ce17067f0653c99aa64e3f99d82ca01f1c 100644 --- a/frontend/test/metabase/scenarios/admin/settings/email.cy.spec.js +++ b/frontend/test/metabase/scenarios/admin/settings/email.cy.spec.js @@ -1,4 +1,4 @@ -import { restore, setupDummySMTP } from "__support__/e2e/cypress"; +import { restore, setupSMTP } from "__support__/e2e/cypress"; describe("scenarios > admin > settings > email settings", () => { beforeEach(() => { @@ -50,16 +50,8 @@ describe("scenarios > admin > settings > email settings", () => { }); it("should send a test email for a valid SMTP configuration", () => { - // We must clear maildev inbox before each run - this will be extracted and automated - cy.request("DELETE", "http://localhost:80/email/all"); - cy.request("PUT", "/api/setting", { - "email-smtp-host": "localhost", - "email-smtp-port": "25", - "email-smtp-username": "admin", - "email-smtp-password": "admin", - "email-smtp-security": "none", - "email-from-address": "mailer@metabase.test", - }); + setupSMTP(); + cy.visit("/admin/settings/email"); cy.findByText("Send test email").click(); cy.findByText("Sent!"); @@ -79,7 +71,7 @@ describe("scenarios > admin > settings > email settings", () => { it("should not offer to save email changes when there aren't any (metabase#14749)", () => { // Make sure some settings are already there - setupDummySMTP(); + setupSMTP(); cy.visit("/admin/settings/email"); cy.findByText("Send test email").scrollIntoView(); diff --git a/frontend/test/metabase/scenarios/permissions/sandboxes.cy.spec.js b/frontend/test/metabase/scenarios/permissions/sandboxes.cy.spec.js index 1b0ea4a936a317e8434183a9bcd1433c4a98ce03..839264ae206e1412eae45a4e6628274d90727442 100644 --- a/frontend/test/metabase/scenarios/permissions/sandboxes.cy.spec.js +++ b/frontend/test/metabase/scenarios/permissions/sandboxes.cy.spec.js @@ -7,6 +7,7 @@ import { popover, restore, remapDisplayValueToFK, + setupSMTP, } from "__support__/e2e/cypress"; import { USER_GROUPS } from "__support__/e2e/cypress_data"; @@ -1033,15 +1034,8 @@ describeWithToken("formatting > sandboxes", () => { }); it("sandboxed user should receive sandboxed dashboard subscription", () => { - cy.request("DELETE", "http://localhost:80/email/all"); - cy.request("PUT", "/api/setting", { - "email-smtp-host": "localhost", - "email-smtp-port": "25", - "email-smtp-username": "admin", - "email-smtp-password": "admin", - "email-smtp-security": "none", - "email-from-address": "mailer@metabase.test", - }); + setupSMTP(); + cy.sandboxTable({ table_id: ORDERS_ID, attribute_remappings: { diff --git a/frontend/test/metabase/scenarios/sharing/reproductions/17658.cy.spec.js b/frontend/test/metabase/scenarios/sharing/reproductions/17658.cy.spec.js index b8e3cb357854db3485d06dc2d265f301a4c0773e..860059f755fe0e26fe85abab4feaef1802339d8d 100644 --- a/frontend/test/metabase/scenarios/sharing/reproductions/17658.cy.spec.js +++ b/frontend/test/metabase/scenarios/sharing/reproductions/17658.cy.spec.js @@ -1,4 +1,4 @@ -import { restore } from "__support__/e2e/cypress"; +import { restore, setupSMTP } from "__support__/e2e/cypress"; describe("issue 17658", () => { beforeEach(() => { @@ -6,7 +6,7 @@ describe("issue 17658", () => { restore(); cy.signInAsAdmin(); - setUpEmail(); + setupSMTP(); moveDashboardToCollection("First collection"); }); @@ -88,14 +88,3 @@ function moveDashboardToCollection(collectionName) { }, ); } - -function setUpEmail() { - cy.request("PUT", "/api/setting", { - "email-smtp-host": "localhost", - "email-smtp-port": "25", - "email-smtp-username": "admin", - "email-smtp-password": "admin", - "email-smtp-security": "none", - "email-from-address": "mailer@metabase.test", - }); -} diff --git a/frontend/test/metabase/scenarios/sharing/reproductions/18009-nodata-creates-subscription-receives-error.cy.spec.js b/frontend/test/metabase/scenarios/sharing/reproductions/18009-nodata-creates-subscription-receives-error.cy.spec.js index 70aa80202b9e477cd953a4284dc4a1c540012cb9..12947b69a37fc5b8e4115bccf0efcef930620e51 100644 --- a/frontend/test/metabase/scenarios/sharing/reproductions/18009-nodata-creates-subscription-receives-error.cy.spec.js +++ b/frontend/test/metabase/scenarios/sharing/reproductions/18009-nodata-creates-subscription-receives-error.cy.spec.js @@ -1,12 +1,11 @@ -import { restore, popover } from "__support__/e2e/cypress"; +import { restore, popover, setupSMTP } from "__support__/e2e/cypress"; describe.skip("issue 18009", () => { beforeEach(() => { restore(); cy.signInAsAdmin(); - cy.request("DELETE", "http://localhost:80/email/all"); - setUpEmail(); + setupSMTP(); cy.signIn("nodata"); }); @@ -39,14 +38,3 @@ describe.skip("issue 18009", () => { }); }); }); - -function setUpEmail() { - cy.request("PUT", "/api/setting", { - "email-smtp-host": "localhost", - "email-smtp-port": "25", - "email-smtp-username": "admin", - "email-smtp-password": "admin", - "email-smtp-security": "none", - "email-from-address": "mailer@metabase.test", - }); -} diff --git a/frontend/test/metabase/scenarios/sharing/subscriptions.cy.spec.js b/frontend/test/metabase/scenarios/sharing/subscriptions.cy.spec.js index c69c0f2a03f2cef5a4253a51149350f6bcd7aa70..c5c1cc87ae108d9bb9ee7d365f991fe57b3ea31f 100644 --- a/frontend/test/metabase/scenarios/sharing/subscriptions.cy.spec.js +++ b/frontend/test/metabase/scenarios/sharing/subscriptions.cy.spec.js @@ -1,6 +1,6 @@ import { restore, - setupDummySMTP, + setupSMTP, describeWithToken, popover, mockSessionProperty, @@ -66,15 +66,7 @@ describe("scenarios > dashboard > subscriptions", () => { describe("with email set up", () => { beforeEach(() => { - cy.request("DELETE", "http://localhost:80/email/all"); - cy.request("PUT", "/api/setting", { - "email-smtp-host": "localhost", - "email-smtp-port": "25", - "email-smtp-username": "admin", - "email-smtp-password": "admin", - "email-smtp-security": "none", - "email-from-address": "mailer@metabase.test", - }); + setupSMTP(); }); describe("with no existing subscriptions", () => { @@ -289,7 +281,7 @@ describe("scenarios > dashboard > subscriptions", () => { beforeEach(() => { cy.skipOn(!!Cypress.env("HAS_ENTERPRISE_TOKEN")); cy.visit(`/dashboard/1`); - setupDummySMTP(); + setupSMTP(); }); describe("with parameters", () => { @@ -310,7 +302,7 @@ describe("scenarios > dashboard > subscriptions", () => { describeWithToken("EE email subscriptions", () => { beforeEach(() => { cy.visit(`/dashboard/1`); - setupDummySMTP(); + setupSMTP(); }); describe("with no parameters", () => {