Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add test for guest to logged in user migration #1544

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

lukevella
Copy link
Owner

@lukevella lukevella commented Feb 3, 2025

Summary by CodeRabbit

  • New Features

    • Guest users can now link polls to an existing account upon signing in, ensuring a smoother transition.
    • A new LoginPage class has been introduced to automate the login process.
  • Improvements

    • Poll creation has been enhanced to accept custom titles for a more personalized experience.
    • Streamlined login and registration flows provide a more intuitive and consistent user journey.

Copy link

vercel bot commented Feb 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2025 0:16am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
landing ⬜️ Skipped (Inspect) Feb 3, 2025 0:16am

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request modifies several test cases by explicitly specifying poll names when calling the poll creation method. The changes update the createPollAndCloseDialog method across multiple tests to accept an object with a name property. Additionally, a new LoginPage class is introduced to encapsulate the login process, and the guest-to-user migration test has been expanded with a case that links a poll to an existing user. Minor adjustments in the registration test also remove unnecessary navigation calls.

Changes

File(s) Change Summary
apps/web/tests/create-delete-poll.spec.ts, apps/web/tests/edit-options.spec.ts, apps/web/tests/vote-and-comment.spec.ts Updated createPollAndCloseDialog calls to include an options object with a name property (e.g., "Monthly Meetup").
apps/web/tests/guest-to-user-migration.spec.ts Updated poll creation calls to pass poll names ("Monthly Meetup" and "Board Meeting") and added a new test case for linking a poll to an existing user; added import for LoginPage.
apps/web/tests/new-poll-page.ts Modified the createPollAndCloseDialog and createPoll method signatures to require a parameter object with a name property; updated internal logic to use dynamic values.
apps/web/tests/login-page.ts Added a new LoginPage class to encapsulate login navigation and verification flow.
apps/web/tests/register-page.ts Removed the call to the goto method in the register function, assuming the registration page is already loaded.

Sequence Diagram(s)

sequenceDiagram
    participant Test as GuestPollTest
    participant NP as NewPollPage
    participant LP as LoginPage

    Test->>NP: createPollAndCloseDialog({ name: "Board Meeting" })
    NP-->>Test: Poll created with "Board Meeting"
    Test->>LP: Navigate to login page (LP.goto())
    LP->>LP: Wait for "Welcome" text
    Test->>LP: login({ email: "[email protected]" })
    LP-->>Test: Verification code processing
    Test->>NP: Assert poll title remains correct
Loading
sequenceDiagram
    participant Tester as Test
    participant LP as LoginPage

    Tester->>LP: goto() → Navigate to "/login"
    LP->>LP: Wait for "Welcome" indicator
    Tester->>LP: login({ email: "[email protected]" })
    LP->>LP: Retrieve and fill verification code
    LP-->>Tester: "Finish Logging In" confirmation
Loading

Possibly related PRs

  • ✅ Add guest to user flow test #1536: The changes in the main PR and the retrieved PR are related as both modify the createPollAndCloseDialog method to include a parameter for the poll name, affecting how polls are created in their respective test cases.
  • 🧑‍💻 Use mailpit as dev/test smtp server #1486: The changes in the main PR, which modify the createPollAndCloseDialog method call to include a parameter object, are directly related to the changes in the retrieved PR, which also modifies the same method call in a similar context.
  • ♻️ Make user session optional #1515: The changes in the main PR, which modify the createPollAndCloseDialog method to accept a parameter for the poll name, are directly related to the changes in the retrieved PR, which also modifies the same method in a similar manner to include a name parameter for poll creation.

Poem

I'm a merry rabbit in code's vast field,
Poll names now bloom, no more conceal.
In tests I hop with options so true,
Linking and logging with a bounce anew.
With carrots of code and ASCII delight,
I celebrate changes from dawn till night!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lukevella lukevella enabled auto-merge (squash) February 3, 2025 12:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/web/tests/login-page.ts (1)

13-25: Consider enhancing error handling and documentation.

While the login flow is well-structured, consider these improvements:

  1. Add error handling for failed verification code retrieval
  2. Add timeout handling for verification code wait
  3. Add JSDoc comments to document the method's behavior and parameters
+/**
+ * Logs in a user using email verification.
+ * @param {Object} params - The login parameters
+ * @param {string} params.email - The email address to log in with
+ * @throws {Error} When verification code retrieval fails
+ */
 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);
+  const code = await getCode(email).catch((error) => {
+    throw new Error(`Failed to retrieve verification code: ${error.message}`);
+  });
   await this.page.getByText("Finish Logging In").waitFor({
+    timeout: 10000
+  });
   await this.page.getByPlaceholder("Enter your 6-digit code").fill(code);
 }
apps/web/tests/new-poll-page.ts (1)

17-40: Consider enhancing error handling and maintainability.

While the implementation is functional, consider these improvements:

  1. Add error handling for failed page interactions
  2. Extract hardcoded strings to constants
  3. Add JSDoc documentation
+const POLL_DEFAULTS = {
+  LOCATION: "Online",
+  DESCRIPTION: "Hey everyone, what time can you meet?",
+  DAYS: [5, 7, 10, 15]
+} as const;
+
+/**
+ * Creates a new poll with the specified name.
+ * @param {Object} params - The poll parameters
+ * @param {string} params.name - The name of the poll
+ * @returns {Promise<PollPage>} The created poll page
+ * @throws {Error} When page interactions fail
+ */
 async createPoll({ name }: { name: string }) {
   const page = this.page;

   await page.fill('[placeholder="Monthly Meetup"]', name);
   // click on label to focus on input
   await page.click('text="Location"');
-  await page.keyboard.type("Online");
+  await page.keyboard.type(POLL_DEFAULTS.LOCATION);

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

-  await page.keyboard.type("Hey everyone, what time can you meet?");
+  await page.keyboard.type(POLL_DEFAULTS.DESCRIPTION);

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

   // Select a few days
-  await page.click("text=/^5$/");
-  await page.click("text=/^7$/");
-  await page.click("text=/^10$/");
-  await page.click("text=/^15$/");
+  for (const day of POLL_DEFAULTS.DAYS) {
+    await page.click(`text=/^${day}$/`).catch((error) => {
+      throw new Error(`Failed to select day ${day}: ${error.message}`);
+    });
+  }

   await page.click('text="Create poll"');

   return new PollPage(page);
 }
apps/web/tests/guest-to-user-migration.spec.ts (1)

51-71: Fix typo in comment and LGTM!

The new test case for guest to logged-in user migration is well-structured and comprehensive. However, there's a typo in the comment on line 63: "lplogin" should be "login".

-    // Step 3: Complete lplogin
+    // Step 3: Complete login
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5abea1e and 514d989.

📒 Files selected for processing (7)
  • apps/web/tests/create-delete-poll.spec.ts (1 hunks)
  • apps/web/tests/edit-options.spec.ts (1 hunks)
  • apps/web/tests/guest-to-user-migration.spec.ts (3 hunks)
  • apps/web/tests/login-page.ts (1 hunks)
  • apps/web/tests/new-poll-page.ts (1 hunks)
  • apps/web/tests/register-page.ts (0 hunks)
  • apps/web/tests/vote-and-comment.spec.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/tests/register-page.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Unit tests
  • GitHub Check: Type check
  • GitHub Check: Integration tests
  • GitHub Check: Linting
🔇 Additional comments (8)
apps/web/tests/login-page.ts (2)

5-6: LGTM! Well-structured constructor.

The constructor follows TypeScript best practices with proper encapsulation and dependency injection.


8-11: LGTM! Robust page navigation.

The method follows Playwright best practices by ensuring the page is fully loaded before proceeding.

apps/web/tests/create-delete-poll.spec.ts (1)

18-18: LGTM! Consistent with method signature update.

The change correctly aligns with the updated createPollAndCloseDialog method signature and is validated by the subsequent title assertion.

apps/web/tests/edit-options.spec.ts (1)

14-16: LGTM! Clean and consistent implementation.

The change correctly implements the updated method signature using proper TypeScript object destructuring.

apps/web/tests/new-poll-page.ts (1)

11-16: LGTM! Well-structured method with clear responsibility.

The method follows good practices with proper type annotations and single responsibility.

apps/web/tests/guest-to-user-migration.spec.ts (2)

5-5: LGTM!

The import of LoginPage class is correctly added to support the new test case.


30-30: LGTM!

The update to createPollAndCloseDialog call with explicit poll name improves test clarity and maintainability.

apps/web/tests/vote-and-comment.spec.ts (1)

24-26: LGTM!

The update to createPollAndCloseDialog call with explicit poll name improves test clarity and maintains consistency with the email subject test on line 58.

@vercel vercel bot temporarily deployed to Preview – landing February 3, 2025 12:13 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/tests/authentication.spec.ts (1)

43-43: Add await and navigation verification.

Good addition of explicit navigation, but it needs two improvements:

  1. Add await to prevent potential race conditions
  2. Add navigation verification to ensure the page loaded successfully

Apply this diff:

-      registerPage.goto();
+      await registerPage.goto();
+      await expect(page.getByText("Create Your Account")).toBeVisible();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 514d989 and 872a305.

📒 Files selected for processing (1)
  • apps/web/tests/authentication.spec.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Unit tests
  • GitHub Check: Integration tests
  • GitHub Check: Type check
  • GitHub Check: Linting

@lukevella lukevella merged commit d4b6879 into main Feb 3, 2025
10 checks passed
@lukevella lukevella deleted the add-guest-user-test branch February 3, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant