test: add emails fixture and apply to existing tests#10560
test: add emails fixture and apply to existing tests#10560nicktrn wants to merge 8 commits intocalcom:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@nicktrn is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you for following the naming conventions! 🙏 |
|
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
📦 Next.js Bundle Analysis for @calcom/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
|
@shivamklr @keithwillcode @zomars as you're currently working on or reviewing mailhog integration Would greatly value your input. |
nicktrn
left a comment
There was a problem hiding this comment.
Ready for review and feedback
| "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next", | ||
| "dev": "next dev", | ||
| "dx": "yarn dev", | ||
| "e2e:mail-server": "ts-node --transpile-only playwright/lib/start-mail-server.ts", |
There was a problem hiding this comment.
for testing purposes, should be built for production
| test("Can reset forgotten password", async ({ page, users }) => { | ||
| const user = await users.create(); | ||
| test("Can reset forgotten password", async ({ page, users, emails }) => { | ||
| const user = await users.create({ email: emails.generateAddress() }); |
There was a problem hiding this comment.
can be further abstracted by moving directly into users fixture, then calling users.create() as usual
| await page.goto("/auth/forgot-password"); | ||
|
|
||
| await page.fill('input[name="email"]', `${user.username}@example.com`); | ||
| await page.fill('input[name="email"]', user.email); |
There was a problem hiding this comment.
email is now scoped to the test
| createdAt: "desc", | ||
| }, | ||
| }); | ||
| const email = await emails.waitForOne(user.email); |
There was a problem hiding this comment.
we wait until the user receives an email, it will return immediately if one is already there
| const bookingUrl = page.url(); | ||
|
|
||
| const [free] = users.get(); | ||
| await emails.waitForMany([/* testEmail, */ free.email]); |
There was a problem hiding this comment.
will throw if not all recipients receive an email - I disabled checking for non-namespaced, hardcoded emails for now. Ideally, test/booking user should also be randomised and email addresses scoped to test
| ws.on("message", (data) => { | ||
| const message = data.toString(); | ||
| debug("received:", message); | ||
| }); |
There was a problem hiding this comment.
bi-directional messaging not currently used, but useful for debugging
| @@ -40,8 +40,6 @@ export default class BaseEmail { | |||
| if (process.env.NEXT_PUBLIC_IS_E2E) { | |||
| global.E2E_EMAILS = global.E2E_EMAILS || []; | |||
| global.E2E_EMAILS.push(this.getNodeMailerPayload()); | |||
There was a problem hiding this comment.
leaving for now as still used by at least one test file
| "ts-node": "^10.9.1", | ||
| "typescript": "^4.9.4" | ||
| "typescript": "^4.9.4", | ||
| "ws": "^8.13.0" |
There was a problem hiding this comment.
| "@types/react-phone-number-input": "^3.0.14", | ||
| "@types/remove-markdown": "^0.3.1", | ||
| "@types/sanitize-html": "^2.9.0", | ||
| "@types/smtp-server": "^3.5.7", |
There was a problem hiding this comment.
| "copy-webpack-plugin": "^11.0.0", | ||
| "detect-port": "^1.3.0", | ||
| "env-cmd": "^10.1.0", | ||
| "mailparser": "^3.6.5", |
There was a problem hiding this comment.
|
This PR is being marked as stale due to inactivity. |
|
Closing as per current email testing plans #10881 (comment) |
What does this PR do?
Adds fixture for email testing. Updates some tests for demo purposes.
Brief API overview:
Fixes #10535
Architectural overview
sequenceDiagram participant Client box Server participant WebSocket participant SMTP end participant Mailer Client-)WebSocket: subscribe Note right of Client: namespaced Mailer-)SMTP: send mail SMTP->>+WebSocket: get subscribers WebSocket-->>-SMTP: subscribers[ ] loop every subscriber SMTP-)WebSocket: forward mail end WebSocket-)Client: forward mail Note right of Client: namespacedType of change
How should this be tested?
yarn e2e playwright/{booking-pages,auth/forgot}Runs fine locally,
but still some things to sort out for ci.and now also on ciMandatory Tasks