Skip to content

Fixed testing cards snapshots for both user groups#22566

Merged
daniellockyer merged 1 commit intomainfrom
fixed-email-snapshots
Mar 19, 2025
Merged

Fixed testing cards snapshots for both user groups#22566
daniellockyer merged 1 commit intomainfrom
fixed-email-snapshots

Conversation

@daniellockyer
Copy link
Contributor

  • this test file is often flaky because the test sends out to both free and paid members at the same time, and depending on the ordering internally, the snapshots can be slightly different
  • AFAIK, we don't have a way to run snapshots against multiple email sends at the same time
  • to workaround that, and to add explicit testing for both groups, I've tweaked the test to run against each user group separately
  • also includes the snapshot changes to make this pass

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

The changes modify the email service integration tests by introducing a parameterized approach. Previously, a single test case existed for rendering the golden post without labs flags. The new implementation replaces this with a loop that creates separate test cases for two statuses: status:free and status:-free. Each iteration now calls the sendEmail function with an additional status argument alongside the lexical data. The logic for stubbing the labs.isSet function remains, with conditional behavior for the contentVisibility flag based on the test case. Additionally, the splitPreheader function continues to process the email data and the matchEmailSnapshot function validates the output against expected snapshots.

Suggested labels

browser-tests

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfd9aa and 15a3887.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/integration/services/email-service/__snapshots__/cards.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • ghost/core/test/integration/services/email-service/cards.test.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
ghost/core/test/integration/services/email-service/cards.test.js (4)
ghost/core/test/unit/api/canary/utils/serializers/output/utils/post-gating.test.js (2) (2)
  • sinon (2-2)
  • labs (5-5)
ghost/core/test/unit/api/canary/utils/serializers/input/posts.test.js (1) (1)
  • sinon (2-2)
ghost/core/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js (1) (1)
  • labs (2-2)
ghost/core/test/e2e-api/content/posts.test.js (1) (1)
  • agent (48-48)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Database tests (Node 22.13.1, mysql8)
  • GitHub Check: Database tests (Node 20.11.1, mysql8)
  • GitHub Check: Database tests (Node 18.12.1, mysql8)
🔇 Additional comments (5)
ghost/core/test/integration/services/email-service/cards.test.js (5)

149-152: Well-designed parameterization to address test flakiness

This is a good solution for handling the test flakiness by running separate tests for each user group. The clear comments explain the reasoning behind the change, making it easier for future developers to understand the approach.


153-162: Effective parameterization of the 'no labs flags' test case

The test now correctly specifies which member status it's running for, and passes that information to the sendEmail function. This will create deterministic test conditions and improve snapshot reliability.


165-180: Proper parameterization of the 'contentVisibility labs flag' test case

The test configuration for the contentVisibility lab flag is now correctly run for each member status, maintaining consistent testing conditions while ensuring deterministic snapshots for each member group.


156-158: Correct addition of status parameter to sendEmail function calls

Adding the status parameter to both sendEmail calls ensures the emails are generated specifically for either free or non-free members, which is essential for creating consistent snapshots.

Also applies to: 173-175


149-181: Overall implementation successfully addresses test flakiness

The parameterized approach effectively solves the test flakiness issue described in the PR objectives. By running separate tests for free and non-free members (rather than concurrently), you've created more deterministic testing conditions that should produce consistent snapshots. The changes are minimal, well-documented, and maintain the original testing logic while making it more specific to each user group.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

refs https://ghost.slack.com/archives/C02G9E68C/p1742391268195829
refs https://ghost.slack.com/archives/C02G9E68C/p1739197454830369

- this test file is often flaky because the test sends out to both free
  and paid members at the same time, and depending on the ordering
  internally, the snapshots can be slightly different
- AFAIK, we don't have a way to run snapshots against multiple email
  sends at the same time
- to workaround that, and to add explicit testing for both groups, I've
  tweaked the test to run against each user group separately
- also includes the snapshot changes to make this pass
@daniellockyer daniellockyer force-pushed the fixed-email-snapshots branch from 8db781e to 15a3887 Compare March 19, 2025 15:22
@daniellockyer daniellockyer merged commit a4b3dd9 into main Mar 19, 2025
26 checks passed
@daniellockyer daniellockyer deleted the fixed-email-snapshots branch March 19, 2025 15:55
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