Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove emailVerified not null from query * Improve query to find existing user * Add test suite to Signup from a Team Invite * Allow importing modules with aliases * Delete created data after all tests * Resolve conflicts * Use teampro instead of pro user and refactor code
- Loading branch information
1 parent
cad77ad
commit 73de0c2
Showing
9 changed files
with
140 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,105 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
import { BASE_URL } from "@lib/config/constants"; | ||
import prisma from "@lib/prisma"; | ||
|
||
import { todo } from "../lib/testUtils"; | ||
|
||
todo("Can signup from a team invite"); | ||
test.describe("Can signup from a team invite", async () => { | ||
let page; | ||
let token: string | undefined; | ||
let signupFromInviteURL = ""; | ||
const team = { name: "Seeded Team", slug: "seeded-team" }; | ||
const testUser = { | ||
email: "test@test.com", | ||
password: "secretpassword123", | ||
validUsername: "test-user", | ||
}; | ||
const usernameAlreadyTaken = "teampro"; | ||
const emailAlreadyTaken = "teampro@example.com"; | ||
|
||
test.use({ storageState: "playwright/artifacts/teamproStorageState.json" }); | ||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
|
||
await page.goto("/settings/teams"); | ||
|
||
await page.waitForSelector(`a[title="${team.name}"]`); | ||
await page.click(`a[title="${team.name}"]`); | ||
|
||
// Send invite to team | ||
await page.click('[data-testid="new-member-button"]'); | ||
await page.fill('input[id="inviteUser"]', testUser.email); | ||
await page.click('[data-testid="invite-new-member-button"]'); | ||
|
||
// Wait for the invite to be sent | ||
await page.waitForSelector(`[data-testid="member-email"][data-email="${testUser.email}"]`); | ||
|
||
const tokenObj = await prisma.verificationRequest.findFirst({ | ||
where: { identifier: testUser.email }, | ||
select: { token: true }, | ||
}); | ||
token = tokenObj?.token; | ||
signupFromInviteURL = `/auth/signup?token=${token}&callbackUrl=${BASE_URL}/settings/teams`; | ||
}); | ||
|
||
test.afterAll(async () => { | ||
// Delete test user | ||
await prisma.user.delete({ | ||
where: { email: testUser.email }, | ||
}); | ||
// Delete verification request | ||
await prisma.verificationRequest.delete({ | ||
where: { token }, | ||
}); | ||
}); | ||
|
||
test("Username already taken", async ({ page }) => { | ||
expect(token).toBeDefined(); | ||
await page.goto(signupFromInviteURL); | ||
// Fill in form | ||
await page.fill('input[name="username"]', usernameAlreadyTaken); | ||
await page.fill('input[name="email"]', testUser.email); | ||
await page.fill('input[name="password"]', testUser.password); | ||
await page.fill('input[name="passwordcheck"]', testUser.password); | ||
await page.press('input[name="passwordcheck"]', "Enter"); // Press Enter to submit | ||
|
||
await expect(page.locator('text="Username already taken"')).toBeVisible(); | ||
}); | ||
|
||
test("Email address is already registered", async ({ page }) => { | ||
expect(token).toBeDefined(); | ||
await page.goto(signupFromInviteURL); | ||
// Fill in form | ||
await page.fill('input[name="username"]', testUser.validUsername); | ||
await page.fill('input[name="email"]', emailAlreadyTaken); | ||
await page.fill('input[name="password"]', testUser.password); | ||
await page.fill('input[name="passwordcheck"]', testUser.password); | ||
await page.press('input[name="passwordcheck"]', "Enter"); // Press Enter to submit | ||
|
||
await expect(page.locator('text="Email address is already registered"')).toBeVisible(); | ||
}); | ||
|
||
test("Successful signup", async ({ page }) => { | ||
expect(token).toBeDefined(); | ||
await page.goto(signupFromInviteURL); | ||
// Fill in form | ||
await page.fill('input[name="username"]', testUser.validUsername); | ||
await page.fill('input[name="email"]', testUser.email); | ||
await page.fill('input[name="password"]', testUser.password); | ||
await page.fill('input[name="passwordcheck"]', testUser.password); | ||
await page.press('input[name="passwordcheck"]', "Enter"); // Press Enter to submit | ||
|
||
await page.waitForNavigation(); | ||
|
||
const createdUser = await prisma.user.findUnique({ | ||
where: { email: testUser.email }, | ||
}); | ||
expect(createdUser).not.toBeNull(); | ||
expect(createdUser?.username).toBe(testUser.validUsername); | ||
expect(createdUser?.password).not.toBeNull(); | ||
expect(createdUser?.emailVerified).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
todo("Can login using 2FA"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73de0c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: