2022-01-26 16:56:22 +00:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
2022-04-14 21:49:51 +00:00
|
|
|
import { WEBAPP_URL } from "@lib/config/constants";
|
2022-01-26 16:56:22 +00:00
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
|
2022-01-07 20:23:37 +00:00
|
|
|
import { todo } from "../lib/testUtils";
|
|
|
|
|
2022-01-26 16:56:22 +00:00
|
|
|
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}"]`);
|
|
|
|
|
2022-04-21 20:32:25 +00:00
|
|
|
const tokenObj = await prisma.verificationToken.findFirst({
|
2022-01-26 16:56:22 +00:00
|
|
|
where: { identifier: testUser.email },
|
|
|
|
select: { token: true },
|
|
|
|
});
|
|
|
|
token = tokenObj?.token;
|
2022-04-14 21:49:51 +00:00
|
|
|
signupFromInviteURL = `/auth/signup?token=${token}&callbackUrl=${WEBAPP_URL}/settings/teams`;
|
2022-01-26 16:56:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
// Delete test user
|
|
|
|
await prisma.user.delete({
|
|
|
|
where: { email: testUser.email },
|
|
|
|
});
|
|
|
|
// Delete verification request
|
2022-04-21 20:32:25 +00:00
|
|
|
await prisma.verificationToken.delete({
|
2022-01-26 16:56:22 +00:00
|
|
|
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 },
|
2022-01-29 18:56:40 +00:00
|
|
|
include: {
|
|
|
|
teams: {
|
|
|
|
include: {
|
|
|
|
team: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-26 16:56:22 +00:00
|
|
|
});
|
2022-01-29 18:56:40 +00:00
|
|
|
// Check that the user was created
|
2022-01-26 16:56:22 +00:00
|
|
|
expect(createdUser).not.toBeNull();
|
|
|
|
expect(createdUser?.username).toBe(testUser.validUsername);
|
|
|
|
expect(createdUser?.password).not.toBeNull();
|
|
|
|
expect(createdUser?.emailVerified).not.toBeNull();
|
2022-01-29 18:56:40 +00:00
|
|
|
// Check that the user accepted the team invite
|
|
|
|
expect(createdUser?.teams).toHaveLength(1);
|
|
|
|
expect(createdUser?.teams[0].team.name).toBe(team.name);
|
|
|
|
expect(createdUser?.teams[0].team.slug).toBe(team.slug);
|
|
|
|
expect(createdUser?.teams[0].role).toBe("MEMBER");
|
|
|
|
expect(createdUser?.teams[0].accepted).toBe(true);
|
2022-01-26 16:56:22 +00:00
|
|
|
});
|
|
|
|
});
|
2022-01-07 20:23:37 +00:00
|
|
|
|
|
|
|
todo("Can login using 2FA");
|