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

Refactored several test files to new E2E framework #22208

Merged
merged 1 commit into from
Feb 17, 2025
Merged

Conversation

daniellockyer
Copy link
Member

  • just some gentle refactors to move them to the new E2E test suite
  • includes the new snapshots with the necessary matchers in place to ensure the tests aren't hardcoded with specific IDs

- just some gentle refactors to move them to the new E2E test suite
- includes the new snapshots with the necessary matchers in place to
  ensure the tests aren't hardcoded with specific IDs
Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Walkthrough

The changes refactor several end-to-end API test suites by replacing the former supertest approach with a new agent-based methodology. In each of the test files for custom theme settings, settings files, and slugs, the initialization now uses an agentProvider alongside fixtureManager to set up and authenticate the test environment with calls like agent.loginAsOwner(). The tests have been updated to utilize concise syntax for making API calls, with assertions shifted to snapshot matching (e.g., matchHeaderSnapshot and matchBodySnapshot) and enhanced status checking methods such as expectStatus and expectEmptyBody. Additionally, there are updates in variable declarations and renamings to support type annotations and improve clarity in the test code.

Suggested labels

browser-tests


📜 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 794a8f0 and f563289.

⛔ Files ignored due to path filters (3)
  • ghost/core/test/e2e-api/admin/__snapshots__/custom-theme-settings.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/admin/__snapshots__/settings-files.test.js.snap is excluded by !**/*.snap
  • ghost/core/test/e2e-api/admin/__snapshots__/slugs.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • ghost/core/test/e2e-api/admin/custom-theme-settings.test.js (6 hunks)
  • ghost/core/test/e2e-api/admin/settings-files.test.js (1 hunks)
  • ghost/core/test/e2e-api/admin/slugs.test.js (1 hunks)
🔇 Additional comments (13)
ghost/core/test/e2e-api/admin/slugs.test.js (4)

1-2: LGTM! Clean import of the new E2E framework utilities.

The imports are well-organized, separating the framework utilities and matchers.


5-6: LGTM! Good use of TypeScript annotations.

The type annotation for the agent variable improves code clarity and maintainability.


8-12: LGTM! Clean test setup using the new framework.

The setup is simplified and more maintainable:

  • Uses agentProvider for agent initialization
  • Properly initializes fixtures
  • Handles authentication cleanly

14-23: LGTM! Well-structured test case using the new framework.

The test case is improved:

  • Uses fluent API for better readability
  • Uses snapshot matching to avoid hardcoding
  • Properly handles dynamic header values
ghost/core/test/e2e-api/admin/settings-files.test.js (4)

1-3: LGTM! Good use of FormData for file handling.

The imports are well-organized and include FormData for proper file upload handling.


8-12: LGTM! Consistent test setup with other files.

The setup follows the same pattern as other refactored files, maintaining consistency across the test suite.


14-23: LGTM! Clean implementation of file download test.

The test case is well-structured:

  • Properly sets Accept header for YAML
  • Uses appropriate status checks
  • Handles dynamic header values consistently

25-42: LGTM! Well-implemented file upload test.

The test case demonstrates good practices:

  • Uses FormData for file upload
  • Sets appropriate content type
  • Maintains consistent assertion pattern
ghost/core/test/e2e-api/admin/custom-theme-settings.test.js (5)

3-4: LGTM! Comprehensive import of framework utilities.

Good use of matchers for handling dynamic values in snapshots.


7-8: LGTM! Proper type annotation.

The type annotation for the agent variable maintains consistency with other files.


10-36: LGTM! Well-structured test setup.

The setup is comprehensive and well-organized:

  • Proper fixture initialization
  • Clean theme activation
  • Good use of custom settings configuration

42-57: LGTM! Clean implementation of Browse tests.

The test case follows the new pattern well:

  • Uses fluent API
  • Properly handles dynamic values in snapshots
  • Clear expectations

111-134: LGTM! Well-implemented error handling tests.

The error tests are thorough:

  • Proper use of sinon for logging stubs
  • Consistent error response handling
  • Good snapshot matching for errors

Also applies to: 135-158

✨ 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.

@daniellockyer daniellockyer merged commit cb0fe4b into main Feb 17, 2025
22 checks passed
@daniellockyer daniellockyer deleted the tests-refactor branch February 17, 2025 16:16
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