Skip to content

Commit

Permalink
✅ Add test for guest to logged in user migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella committed Feb 3, 2025
1 parent 5abea1e commit 514d989
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/web/tests/create-delete-poll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test.describe.serial(() => {
test("create a new poll", async () => {
const newPollPage = new NewPollPage(page);

await newPollPage.createPollAndCloseDialog();
await newPollPage.createPollAndCloseDialog({ name: "Monthly Meetup" });

await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");
});
Expand Down
4 changes: 3 additions & 1 deletion apps/web/tests/edit-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test.describe("edit options", () => {
page = await browser.newPage();
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
const pollPage = await newPollPage.createPollAndCloseDialog();
const pollPage = await newPollPage.createPollAndCloseDialog({
name: "Monthly Meetup",
});
await pollPage.addParticipant("Mark");
editOptionsPage = await pollPage.editOptions();
});
Expand Down
25 changes: 24 additions & 1 deletion apps/web/tests/guest-to-user-migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from "@playwright/test";
import { prisma } from "@rallly/database";
import { NewPollPage } from "tests/new-poll-page";

import { LoginPage } from "./login-page";
import { deleteAllMessages } from "./mailpit/mailpit";
import { RegisterPage } from "./register-page";

Expand All @@ -26,7 +27,7 @@ test.describe.serial(() => {
}) => {
// Step 1: Create a poll as guest
const newPollPage = new NewPollPage(page);
await newPollPage.createPollAndCloseDialog();
await newPollPage.createPollAndCloseDialog({ name: "Monthly Meetup" });
await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");

// Step 2: Navigate to registration
Expand All @@ -46,4 +47,26 @@ test.describe.serial(() => {
await page.click("text=Monthly Meetup");
await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");
});

test("guest user can create a poll and link it to existing user", async ({
page,
}) => {
// Step 1: Create a poll as guest
const newPollPage = new NewPollPage(page);
await newPollPage.createPollAndCloseDialog({ name: "Board Meeting" });
await expect(page.getByTestId("poll-title")).toHaveText("Board Meeting");

// Step 2: Navigate to registration
await page.getByRole("link", { name: "Login" }).click();
await expect(page).toHaveURL(/login/);

// Step 3: Complete lplogin
const loginPage = new LoginPage(page);
await loginPage.login({
email: TEST_USER_EMAIL,
});

// Step 4: Navigate back to the poll
await expect(page.getByTestId("poll-title")).toHaveText("Board Meeting");
});
});
26 changes: 26 additions & 0 deletions apps/web/tests/login-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Page } from "@playwright/test";

import { getCode } from "./utils";

export class LoginPage {
constructor(private readonly page: Page) {}

async goto() {
await this.page.goto("/login");
await this.page.getByText("Welcome").waitFor();
}

async login({ email }: { email: string }) {
// Fill in registration form
await this.page.getByPlaceholder("[email protected]").fill(email);

await this.page
.getByRole("button", { name: "Continue with Email", exact: true })
.click();

// Handle verification code
const code = await getCode(email);
await this.page.getByText("Finish Logging In").waitFor();
await this.page.getByPlaceholder("Enter your 6-digit code").fill(code);
}
}
12 changes: 6 additions & 6 deletions apps/web/tests/new-poll-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ export class NewPollPage {
await this.page.goto("/new");
}

async createPollAndCloseDialog() {
async createPollAndCloseDialog({ name }: { name: string }) {
await this.goto();
const pollPage = await this.createPoll();
const pollPage = await this.createPoll({ name });
await pollPage.closeDialog();
return pollPage;
}
async createPoll() {
async createPoll({ name }: { name: string }) {
const page = this.page;

await page.fill('[placeholder="Monthly Meetup"]', "Monthly Meetup");
await page.fill('[placeholder="Monthly Meetup"]', name);
// click on label to focus on input
await page.click('text="Location"');
await page.keyboard.type("Joe's Coffee Shop");
await page.keyboard.type("Online");

await page.click('text="Description"');

await page.keyboard.type("This is a test description");
await page.keyboard.type("Hey everyone, what time can you meet?");

await page.click('[title="Next month"]');

Expand Down
1 change: 0 additions & 1 deletion apps/web/tests/register-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class RegisterPage {
}

async register({ name, email }: { name: string; email: string }) {
await this.goto();
// Fill in registration form
await this.page.getByPlaceholder("Jessie Smith").fill(name);
await this.page.getByPlaceholder("[email protected]").fill(email);
Expand Down
4 changes: 3 additions & 1 deletion apps/web/tests/vote-and-comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ test.describe(() => {
);
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
pollPage = await newPollPage.createPollAndCloseDialog();
pollPage = await newPollPage.createPollAndCloseDialog({
name: "Monthly Meetup",
});
});

test("should call touch endpoint", async () => {
Expand Down

0 comments on commit 514d989

Please sign in to comment.