From 6f27fa8063848c01a03a4b508b50df8f3dc06f82 Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Tue, 19 Sep 2023 15:42:00 +0100 Subject: [PATCH] Signup with token test --- apps/web/playwright/signup.e2e.ts | 66 +++++++++++++++++++ apps/web/public/static/locales/en/common.json | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/apps/web/playwright/signup.e2e.ts b/apps/web/playwright/signup.e2e.ts index 6069b633ea..5b8a9b9d54 100644 --- a/apps/web/playwright/signup.e2e.ts +++ b/apps/web/playwright/signup.e2e.ts @@ -1,4 +1,5 @@ import { expect } from "@playwright/test"; +import { randomBytes } from "crypto"; import { IS_CALCOM } from "@calcom/lib/constants"; @@ -125,4 +126,69 @@ test.describe("Signup Flow Test", async () => { // Check that the URL matches the expected URL expect(page.url()).toContain("/auth/verify-email"); }); + test("Signup with token prefils correct fields", async ({ page, users, prisma }) => { + //Create a user and create a token + const token = randomBytes(32).toString("hex"); + + // @shivram we can probably create a fixture for this logic. + const createdtoken = await prisma.verificationToken.create({ + data: { + identifier: "rick-team@example.com", + token, + expires: new Date(new Date().setHours(168)), // +1 week + team: { + create: { + name: "Rick's Team", + slug: "ricks-team", + }, + }, + }, + }); + + // create a user with the same email as the token + const rickTeamUser = await prisma.user.create({ + data: { + email: "rick-team@example.com", + username: "rick-team", + }, + }); + + // Create provitional membership + await prisma.membership.create({ + data: { + teamId: createdtoken.teamId ?? -1, + userId: rickTeamUser.id, + role: "ADMIN", + accepted: false, + }, + }); + + const signupUrlWithToken = `/signup?token=${token}`; + + await page.goto(signupUrlWithToken); + + const usernameField = page.locator('input[name="username"]'); + const emailField = page.locator('input[name="email"]'); + + expect(await usernameField.inputValue()).toBe("rick-team"); + expect(await emailField.inputValue()).toBe("rick-team@example.com"); + + // Clean up the user and token + await prisma.user.delete({ + where: { + id: rickTeamUser.id, + }, + }); + await prisma.verificationToken.delete({ + where: { + id: createdtoken.id, + }, + }); + + await prisma.team.delete({ + where: { + id: createdtoken.teamId ?? -1, + }, + }); + }); }); diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 48603db3d5..64e8fc40f1 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -67,7 +67,7 @@ "cannot_repackage_codebase": "You can not repackage or sell the codebase", "acquire_license": "Acquire a commercial license to remove these terms by emailing", "terms_summary": "Summary of terms", - "signing_up_terms":"By signing up, you agree to our <1> Terms of Service and <2>Privacy Policy.", + "signing_up_terms":"By signing up, you agree to our <1>Terms of Service and <2>Privacy Policy.", "open_env": "Open .env and agree to our License", "env_changed": "I've changed my .env", "accept_license": "Accept License",