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

chore(test): add e2e tests for moderation #254

Merged
merged 1 commit into from
Jan 2, 2025
Merged

Conversation

dtfiedler
Copy link
Collaborator

No description provided.

Copy link

codecov bot commented Dec 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.95%. Comparing base (3cdac7e) to head (81e82e1).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #254   +/-   ##
========================================
  Coverage    70.95%   70.95%           
========================================
  Files           35       35           
  Lines         8997     8997           
  Branches       523      523           
========================================
  Hits          6384     6384           
  Misses        2611     2611           
  Partials         2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error @permaweb/aoconnect@0.0.57: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.

📝 Walkthrough

Walkthrough

The pull request introduces new moderation endpoints to the AR.IO Gateway OpenAPI specification and adds corresponding end-to-end tests for these features. Specifically, two new administrative PUT endpoints are added for blocking and unblocking ARNS names: /ar-io/admin/block-name and /ar-io/admin/unblock-name. The changes include updating the OpenAPI documentation and implementing comprehensive end-to-end tests to verify the moderation functionality, ensuring proper authentication and access control.

Changes

File Change Summary
docs/openapi.yaml Added two new administrative endpoints:
- PUT /ar-io/admin/block-name for blocking ARNS names
- PUT /ar-io/admin/unblock-name for unblocking ARNS names
test/end-to-end/moderation.test.ts Implemented end-to-end tests for moderation functionality, covering:
- Blocking and unblocking ARNS names
- Blocking and unblocking transactions
- Authentication and authorization checks

Sequence Diagram

sequenceDiagram
    participant Client
    participant Gateway
    participant AuthService

    Client->>Gateway: PUT /ar-io/admin/block-name
    Gateway->>AuthService: Validate API Key
    alt Valid API Key
        Gateway->>Gateway: Block ARNS Name
        Gateway-->>Client: 200 OK
    else Invalid API Key
        Gateway-->>Client: 401 Unauthorized
    end

    Client->>Gateway: PUT /ar-io/admin/unblock-name
    Gateway->>AuthService: Validate API Key
    alt Valid API Key
        Gateway->>Gateway: Unblock ARNS Name
        Gateway-->>Client: 200 OK
    else Invalid API Key
        Gateway-->>Client: 401 Unauthorized
    end
Loading

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

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: 1

🧹 Nitpick comments (1)
test/end-to-end/moderation.test.ts (1)

84-107: Add test coverage for already-blocked scenarios.

Currently, the test checks a straightforward block scenario and then verifies the resource returns 404 when blocked. Consider adding a test for when an ARNS name is already blocked, to confirm that blocking it again doesn’t produce unwanted side effects.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3cdac7e and 81e82e1.

📒 Files selected for processing (2)
  • docs/openapi.yaml (1 hunks)
  • test/end-to-end/moderation.test.ts (1 hunks)
🔇 Additional comments (5)
test/end-to-end/moderation.test.ts (4)

39-40: Test suite is well-structured.

The top-level “Moderation” describe block effectively organizes the E2E tests, providing clarity on what’s being tested for administrative blocking features.


64-83: Good use of 401 checks to verify authorization.

This section thoroughly tests for unauthorized access, ensuring that the correct error code is returned when an invalid API key is presented. This is critical for security and correctness.


120-149: Verification of final unblocked state is solid.

The flow of re-blocking the name before unblocking it ensures the test environment is well-controlled. Good job verifying a 200 after unblocking.


152-200: Consider verifying “unblock transaction” behavior.

While blocking a transaction in this suite is correct, it might be beneficial to provide a similar test for unblocking a transaction, if such functionality exists or is planned.

Do you want me to open a new GitHub issue to track adding an “unblock transaction” endpoint and tests if that functionality is needed?

docs/openapi.yaml (1)

776-805: Consistency with code usage verified.

The /ar-io/admin/block-name endpoint’s request body fields match the tested keys in “moderation.test.ts”, ensuring the specification is accurately aligned with the actual implementation.

Comment on lines +805 to +827
'/ar-io/admin/unblock-name':
put:
tags: [Admin]
summary: Unblock an ARNS name.
description: Unblock an ARNS name so your AR.IO Gateway will serve it again.
operationId: adminUnblockName
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: The name you want to unblock.
responses:
'200':
description: Successful operation.
'401':
description: Unauthorized, API key likely incorrect.
security:
- bearerAuth: []
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add 400 or 404 specification for missing or unknown ARNS name.

Currently, the specification includes 200 and 401 responses. Consider defining a 400 or 404 response to cover scenarios where the requested name does not exist or is invalid.

@dtfiedler dtfiedler merged commit 17a04dd into develop Jan 2, 2025
6 checks passed
@dtfiedler dtfiedler deleted the fix-block-name branch January 2, 2025 20:07
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.

3 participants