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

Feat/be/check controller tests, #924 #929

Merged
merged 7 commits into from
Oct 12, 2024

Conversation

ajhollid
Copy link
Collaborator

This PR adds unit tests to for the check controller

  • Add unit tests for check controller
    • createCheck
    • getChecks
    • getTeamChecks
    • deleteChecks
    • deleteChecksByTeamId
    • updateChecksTTL


req = {
body: {},
headers: { authorization: "Bearer token" },

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer token" is used as
authorization header
.
Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

This pull request introduces a comprehensive suite of unit tests for the checkController module. It includes tests for various functionalities such as creating, retrieving, deleting, and updating checks. The tests are organized into distinct suites for each controller function and utilize the sinon library for mocking. Each suite includes setup and teardown processes to ensure a clean testing environment, validating both successful operations and error handling for invalid inputs.

Changes

File Path Change Summary
Server/tests/controllers/checkController.test.js Added unit tests for checkController functions: createCheck, getChecks, getTeamChecks, deleteChecks, deleteChecksByTeamId, and updateChecksTTL, including parameter validation and error handling.

Possibly related PRs

  • Feat/server auth controller tests #922: The changes in this PR involve the checkController functions (createCheck, getChecks, getTeamChecks, deleteChecks, deleteChecksByTeamId, and updateChecksTTL), which are also tested in the main PR, indicating a direct relationship in terms of functionality being validated.

Suggested reviewers

  • marcelluscaio
  • jennifer-gan

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

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

@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

🧹 Outside diff range and nitpick comments (2)
Server/tests/controllers/checkController.test.js (2)

14-28: Refactor repetitive test setup code

The beforeEach blocks in multiple test suites contain duplicated code for setting up req, res, next, and stubs. Consider extracting common setup logic into shared helper functions or using a higher-level beforeEach to reduce redundancy and improve maintainability.

Also applies to: 91-105, 146-159, 200-212, 251-263, 304-324


27-27: Remove unused stub handleError

The stub handleError is declared but not used in the tests. Removing unused variables can help keep the code clean and readable.

Apply this diff to remove the unused stub:

-        handleError = sinon.stub();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 28a4d18 and 0a805c1.

📒 Files selected for processing (1)
  • Server/tests/controllers/checkController.test.js (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeQL
Server/tests/controllers/checkController.test.js

[failure] 311-311: Hard-coded credentials
The hard-coded value "Bearer token" is used as authorization header.


req = {
body: {},
headers: { authorization: "Bearer token" },
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using hard-coded authorization headers in tests

Using hard-coded credentials like "Bearer token" can pose security risks and may lead to unintended behavior. Consider using a mock token or securely generating one for test purposes.

Apply this diff to replace the hard-coded token with a mocked token:

-      headers: { authorization: "Bearer token" },
+      headers: { authorization: `Bearer ${mockedToken}` },

Where mockedToken is a token generated or mocked appropriately for the test context.

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 GitHub Check: CodeQL

[failure] 311-311: Hard-coded credentials
The hard-coded value "Bearer token" is used as authorization header.

@ajhollid ajhollid changed the title Feat/be/check controller tests Feat/be/check controller tests, #924 Oct 11, 2024
Copy link
Contributor

@jennifer-gan jennifer-gan left a comment

Choose a reason for hiding this comment

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

coverage 100%? cool for check controller test

@ajhollid ajhollid merged commit 5d72e80 into develop Oct 12, 2024
2 of 3 checks passed
@ajhollid ajhollid deleted the feat/be/check-controller-tests branch October 12, 2024 00:27
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.

2 participants