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

Remove unused DB method, add tests for pageSpeedCheckModule #1144

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

ajhollid
Copy link
Collaborator

This PR adds tests for the pageSpeedCheck DB module

  • Remove unsued method from module
  • Add tests

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

Auto Pull Request Review from LlamaPReview

1. Overview

1.1 PR Summary

  • Business value and requirements alignment: The PR aims to enhance code maintainability and test coverage by removing an unused DB method and adding comprehensive tests for the pageSpeedCheckModule.
  • Key components modified:
    • Server/db/mongo/MongoDB.js: Removal of an unused import and method call.
    • Server/db/mongo/modules/pageSpeedCheckModule.js: Removal of the unused getPageSpeedChecks method.
    • Server/tests/db/pageSpeedCheckModule.test.js: Addition of unit tests for createPageSpeedCheck and deletePageSpeedChecksByMonitorId methods.
  • Impact assessment: The changes simplify the codebase without affecting existing functionality, improving readability and maintainability.
  • System dependencies and integration impacts: No significant impact on integration points as the changes are internal to the module.

1.2 Architecture Changes

  • System design modifications: No significant changes to the overall system design.
  • Component interactions: Removal of unused method streamlines the interaction within the pageSpeedCheckModule.
  • Integration points: No impact on integration points.

2. Detailed Technical Analysis

2.1 Code Logic Deep-Dive

Core Logic Changes

File Path: Server/db/mongo/MongoDB.js

  • Submitted PR Code:
    ---
    +++
    @@ -111,21 +111,20 @@
    	editMonitor,
    	addDemoMonitors,
    } from "./modules/monitorModule.js";
    
    //****************************************
    // Page Speed Checks
    //****************************************
    
    import {
    	createPageSpeedCheck,
    -	getPageSpeedChecks,
    	deletePageSpeedChecksByMonitorId,
    } from "./modules/pageSpeedCheckModule.js";
    
    //****************************************
    // Hardware Checks
    //****************************************
    import { createHardwareCheck } from "./modules/hardwareCheckModule.js";
    
    //****************************************
    // Checks
    @@ -205,21 +204,20 @@
    	addDemoMonitors,
    	createCheck,
    	getChecksCount,
    	getChecks,
    	getTeamChecks,
    	deleteChecks,
    	deleteChecksByTeamId,
    	updateChecksTTL,
    	deleteMonitorsByUserId,
    	createPageSpeedCheck,
    -	getPageSpeedChecks,
    	deletePageSpeedChecksByMonitorId,
    	createHardwareCheck,
    	createMaintenanceWindow,
    	getMaintenanceWindowsByTeamId,
    	getMaintenanceWindowById,
    	getMaintenanceWindowsByMonitorId,
    	deleteMaintenanceWindowById,
    	deleteMaintenanceWindowByMonitorId,
    	deleteMaintenanceWindowByUserId,
    	editMaintenanceWindowById,
  • Analysis:
    • The removal of the getPageSpeedChecks method from the import statements and the export list simplifies the code and reduces unnecessary references.
    • No impact on other methods or the overall functionality of the MongoDB module.
  • LlamaPReview Suggested Improvements: None required; the change is straightforward and beneficial.

File Path: Server/db/mongo/modules/pageSpeedCheckModule.js

  • Submitted PR Code:
    ---
    +++
    @@ -19,48 +19,29 @@
    		}).save();
    		return pageSpeedCheck;
    	} catch (error) {
    		error.service = SERVICE_NAME;
    		error.method = "createPageSpeedCheck";
    		throw error;
    	}
    };
    
    /**
    - * Get all PageSpeed checks for a monitor
    - * @async
    - * @param {string} monitorId
    - * @returns {Promise<Array<PageSpeedCheck>>}
    - * @throws {Error}
    - */
    -
    -const getPageSpeedChecks = async (monitorId) => {
    -	try {
    -		const pageSpeedChecks = await PageSpeedCheck.find({ monitorId });
    -		return pageSpeedChecks;
    -	} catch (error) {
    -		error.service = SERVICE_NAME;
    -		error.method = "getPageSpeedChecks";
    -		throw error;
    -	}
    -};
    -
    -/**
     * Delete all PageSpeed checks for a monitor
     * @async
     * @param {string} monitorId
     * @returns {number}
     * @throws {Error}
     */
    
     const deletePageSpeedChecksByMonitorId = async (monitorId) => {
    	try {
    		const result = await PageSpeedCheck.deleteMany({ monitorId });
    		return result.deletedCount;
    	} catch (error) {
    		error.service = SERVICE_NAME;
    		error.method = "deletePageSpeedChecksByMonitorId";
    		throw error;
    	}
    };
    
    -export { createPageSpeedCheck, getPageSpeedChecks, deletePageSpeedChecksByMonitorId };
    +export { createPageSpeedCheck, deletePageSpeedChecksByMonitorId };
  • Analysis:
    • The removal of the getPageSpeedChecks method and its associated import and export statements reduces code complexity.
    • No impact on the functionality of other methods within the module.
  • LlamaPReview Suggested Improvements: None required; the change is straightforward and beneficial.

File Path: Server/tests/db/pageSpeedCheckModule.test.js

  • Submitted PR Code:
    + import sinon from "sinon";
    + import PageSpeedCheck from "../../db/models/PageSpeedCheck.js";
    + import {
    + 	createPageSpeedCheck,
    + 	deletePageSpeedChecksByMonitorId,
    + } from "../../db/mongo/modules/pageSpeedCheckModule.js";
    +
    + const mockPageSpeedCheck = {
    + 	monitorId: "monitorId",
    + 	bestPractices: 1,
    + 	seo: 1,
    + 	performance: 1,
    + };
    +
    + const mockDeletedResult = { deletedCount: 1 };
    +
    + describe("pageSpeedCheckModule", () => {
    + 	let pageSpeedCheckSaveStub, pageSpeedCheckDeleteManyStub;
    + 	beforeEach(() => {
    + 		pageSpeedCheckSaveStub = sinon.stub(PageSpeedCheck.prototype, "save");
    + 		pageSpeedCheckDeleteManyStub = sinon.stub(PageSpeedCheck, "deleteMany");
    + 	});
    +
    + 	afterEach(() => {
    + 		sinon.restore();
    + 	});
    +
    + 	describe("createPageSpeedCheck", () => {
    + 		it("should return a page speed check", async () => {
    + 			pageSpeedCheckSaveStub.resolves(mockPageSpeedCheck);
    + 			const pageSpeedCheck = await createPageSpeedCheck(mockPageSpeedCheck);
    + 			expect(pageSpeedCheck).to.deep.equal(mockPageSpeedCheck);
    + 		});
    +
    + 		it("should handle an error", async () => {
    + 			const err = new Error("test error");
    + 			pageSpeedCheckSaveStub.rejects(err);
    + 			try {
    + 				await expect(createPageSpeedCheck(mockPageSpeedCheck));
    + 			} catch (error) {
    + 				expect(error).to.exist;
    + 				expect(error).to.deep.equal(err);
    + 			}
    + 		});
    + 	});
    +
    + 	describe("deletePageSpeedChecksByMonitorId", () => {
    + 		it("should return the number of deleted checks", async () => {
    + 			pageSpeedCheckDeleteManyStub.resolves(mockDeletedResult);
    + 			const result = await deletePageSpeedChecksByMonitorId("monitorId");
    + 			expect(result).to.deep.equal(mockDeletedResult.deletedCount);
    + 		});
    +
    + 		it("should handle an error", async () => {
    + 			const err = new Error("test error");
    + 			pageSpeedCheckDeleteManyStub.rejects(err);
    + 			try {
    + 				await expect(deletePageSpeedChecksByMonitorId("monitorId"));
    + 			} catch (error) {
    + 				expect(error).to.exist;
    + 				expect(error).to.deep.equal(err);
    + 			}
    + 		});
    + 	});
    + });
  • Analysis:
    • The tests cover both successful and error scenarios for createPageSpeedCheck and deletePageSpeedChecksByMonitorId.
    • Uses Sinon for stubbing and Mocha for assertions, ensuring thorough coverage.
  • LlamaPReview Suggested Improvements: None required; the tests are well-structured and comprehensive.

Cross-cutting Concerns

  • Edge Cases in Testing: The initial review did not delve into potential edge cases for the createPageSpeedCheck and deletePageSpeedChecksByMonitorId methods. For example, what happens if the monitorId is null or an empty string?

2.2 Implementation Quality

  • Code Structure:
    • The code is well-organized with clear separation of concerns.
    • Modularity is maintained by keeping related functionality within the same module.
  • Error Handling:
    • Error handling is robust, with proper error messages and service identification.
    • Tests cover both successful and error scenarios, ensuring comprehensive error handling.
  • Performance Considerations:
    • No apparent performance issues introduced by the changes.
    • Removal of unused code improves readability and maintainability.

3. Critical Findings

3.1 Potential Issues

  • 🔴 Critical Issues

    • None identified.
  • 🟡 Warnings

    • Potential Dependencies: The initial review did not consider whether any other modules or services depend on the getPageSpeedChecks method. Even if the method is unused within the pageSpeedCheckModule, it might be used elsewhere in the codebase.
      • Potential risks: If the getPageSpeedChecks method is used elsewhere, removing it could cause runtime errors.
      • Suggested improvements: Perform a thorough search across the codebase to ensure no other modules use this method. If found, update those modules accordingly.

3.2 Code Quality Concerns

  • Documentation for Removed Method: The removal of the getPageSpeedChecks method should be documented in the repository's change log or release notes to inform other developers about the deprecation.

4. Security Assessment

4.1 Security Considerations

  • Error Propagation: The error handling in the methods is robust, but the initial review did not discuss how these errors are propagated up the call stack and how they are handled at higher levels. This is important for ensuring that errors are logged and communicated properly to the end-user.

4.2 Vulnerability Analysis

  • Potential security risks: No new security risks introduced.
  • Mitigation strategies: Ensure that all layers of the application consistently handle and propagate errors. Update documentation to reflect the expected error handling behavior.

5. Testing Strategy

5.1 Test Coverage

  • Unit test analysis: The tests cover both successful and error scenarios for createPageSpeedCheck and deletePageSpeedChecksByMonitorId.
  • Edge cases coverage: The initial review did not consider edge cases such as null or empty monitorId.

5.2 Test Recommendations

Suggested Test Cases

  • Add Edge Case Tests:
    describe("createPageSpeedCheck", () => {
        // Existing tests...
    
        it("should handle null monitorId", async () => {
            const err = new Error("monitorId is required");
            pageSpeedCheckSaveStub.rejects(err);
            try {
                await createPageSpeedCheck({ monitorId: null, bestPractices: 1, seo: 1, performance: 1 });
            } catch (error) {
                expect(error).to.exist;
                expect(error).to.deep.equal(err);
            }
        });
    });
    
    describe("deletePageSpeedChecksByMonitorId", () => {
        // Existing tests...
    
        it("should handle null monitorId", async () => {
            const err = new Error("monitorId is required");
            pageSpeedCheckDeleteManyStub.rejects(err);
            try {
                await deletePageSpeedChecksByMonitorId(null);
            } catch (error) {
                expect(error).to.exist;
                expect(error).to.deep.equal(err);
            }
        });
    });
  • Coverage improvements: Expand the test suite to include edge cases such as null or empty monitorId, and validate the behavior for different data types and values.

6. Documentation & Maintenance

  • Documentation updates needed: Document the removal of the getPageSpeedChecks method in the repository's change log or release notes.
  • Long-term maintenance considerations: Ensure consistent naming conventions for test variables and functions.

7. Deployment & Operations

  • Deployment impact and strategy: No significant impact on deployment.
  • Key operational considerations: Ensure that all layers of the application consistently handle and propagate errors.

8. Summary & Recommendations

8.1 Key Action Items

  1. Critical Changes (P0): None
  2. Important Improvements (P1):
    • Perform a thorough search across the codebase to ensure no other modules use the getPageSpeedChecks method.
  3. Suggested Enhancements (P2):
    • Add comments to the new test cases.
    • Ensure consistent naming conventions for test variables and functions.
    • Document the removal of the getPageSpeedChecks method in the repository's change log or release notes.

8.2 Future Considerations

  • Technical evolution path: Continue to improve test coverage and edge case handling.
  • Business capability evolution: Enhance monitoring and alerting capabilities.
  • System integration impacts: Ensure consistent error handling and propagation across the application.

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

This pull request involves the removal of the getPageSpeedChecks function from both the MongoDB.js and pageSpeedCheckModule.js files. The changes affect the module's interface, as this function is no longer available for retrieving page speed checks. Additionally, a new test suite is introduced for the pageSpeedCheckModule, which includes tests for the remaining functions, ensuring their proper functionality and error handling.

Changes

File Change Summary
Server/db/mongo/MongoDB.js Removed getPageSpeedChecks from import statements and exported object.
Server/db/mongo/modules/pageSpeedCheckModule.js Removed getPageSpeedChecks(monitorId) method and updated export statement to exclude it.
Server/tests/db/pageSpeedCheckModule.test.js Introduced a new test suite for pageSpeedCheckModule, testing createPageSpeedCheck and deletePageSpeedChecksByMonitorId.

Possibly related PRs

  • Pagespeed dashboard revamp #841: The getPageSpeedChecks function was removed from both MongoDB.js and pageSpeedCheckModule.js, indicating a direct relationship between the changes in this PR and the removal of the same function in the pageSpeedCheckModule.js.
  • Add missing test cases for pagespeed and hardware monitor types #1124: This PR adds missing test cases for the pagespeed monitor type, which is directly related to the functionality of the getPageSpeedChecks function that was removed in the main PR.

Suggested reviewers

  • shyna92
  • jennifer-gan
  • marcelluscaio

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

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

8-13: Yo dawg, let's beef up those test cases! 🍝

The mock data could use some additional edge cases to make these tests more robust. Consider adding test cases for:

  • Negative performance scores
  • Zero scores
  • Maximum possible scores (100)
  • Missing optional fields

19-22: Mom's spaghetti says we should verify our stubs! 🍝

While the stub setup is clean, we should add type verification to ensure the stubs are created successfully:

 beforeEach(() => {
   pageSpeedCheckSaveStub = sinon.stub(PageSpeedCheck.prototype, "save");
   pageSpeedCheckDeleteManyStub = sinon.stub(PageSpeedCheck, "deleteMany");
+  expect(pageSpeedCheckSaveStub).to.be.a('function');
+  expect(pageSpeedCheckDeleteManyStub).to.be.a('function');
 });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b554074 and a221326.

📒 Files selected for processing (3)
  • Server/db/mongo/MongoDB.js (0 hunks)
  • Server/db/mongo/modules/pageSpeedCheckModule.js (1 hunks)
  • Server/tests/db/pageSpeedCheckModule.test.js (1 hunks)
💤 Files with no reviewable changes (1)
  • Server/db/mongo/MongoDB.js
🔇 Additional comments (4)
Server/db/mongo/modules/pageSpeedCheckModule.js (3)

47-47: Export statement properly updated, yo!

The export statement has been cleanly updated to remove the unused getPageSpeedChecks function. Straight fire! 🔥


Line range hint 1-47: Palms are sweaty but the error handling is solid!

The remaining functions have consistent error handling with proper service and method attribution. Knees weak with appreciation for this clean code! 💯


Line range hint 1-47: Verify no remaining references to the removed function

Mom's spaghetti tells me we should verify there aren't any lingering references to the removed getPageSpeedChecks function in the codebase.

✅ Verification successful

Yo, the function's gone without a trace - we're clean!

After sweating through comprehensive searches across the entire codebase, there's no sign of any remaining references to getPageSpeedChecks. The function's been cleaned up properly, like mom's kitchen after spaghetti night - not a single trace left behind.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to getPageSpeedChecks

# Look for direct function calls or string references
rg -i "getPageSpeedChecks"

# Look for potential destructured imports of the function
ast-grep --pattern 'import { $$$ getPageSpeedChecks $$$ } from "$$_"'

Length of output: 98


Script:

#!/bin/bash
# Let's try a more comprehensive search approach with context

# Search for any references to getPageSpeedChecks in JavaScript/TypeScript files
rg -t js -t ts "getPageSpeedChecks" -B 2 -A 2

# Look for any imports from the module that might have included this function
rg -t js -t ts "from ['\"].*pageSpeedCheckModule['\"]" -B 1 -A 1

# Search for any potential test files that might reference this function
fd -e test.js -e spec.js -X rg "getPageSpeedChecks"

# Look for any router or controller files that might use this function
fd -e router.js -e controller.js -X rg "getPageSpeedChecks"

Length of output: 228

Server/tests/db/pageSpeedCheckModule.test.js (1)

3-6: Lose yourself in the coverage - let's verify! 🍝

Let's verify that we're testing all exported functions from the module:

✅ Verification successful

Yo, the test coverage is on point like mom's spaghetti! 🍝

Looking at the exports and test coverage, we're actually in a good spot! The module exports exactly two functions (createPageSpeedCheck and deletePageSpeedChecksByMonitorId), and our test file has comprehensive coverage for both:

  • Each function has a success case test
  • Each function has an error handling test

The test structure is clean and matches the module's exports perfectly. No spaghetti code here, just clean testing!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all exported functions from pageSpeedCheckModule.js
ast-grep --pattern 'export function $FUNC' Server/db/mongo/modules/pageSpeedCheckModule.js

Length of output: 92


Script:

#!/bin/bash
# Let's try a different pattern to catch exports
rg "export" Server/db/mongo/modules/pageSpeedCheckModule.js -A 1

# Also check the actual test file to see what we're testing
rg "test|describe|it\(" Server/tests/db/pageSpeedCheckModule.test.js

Length of output: 629

Comment on lines +54 to +63
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckDeleteManyStub.rejects(err);
try {
await expect(deletePageSpeedChecksByMonitorId("monitorId"));
} catch (error) {
expect(error).to.exist;
expect(error).to.deep.equal(err);
}
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Same spaghetti, different plate - fix this error handling! 🍝

This error handling test has the same issue as the previous one:

-try {
-  await expect(deletePageSpeedChecksByMonitorId("monitorId"));
-} catch (error) {
-  expect(error).to.exist;
-  expect(error).to.deep.equal(err);
-}
+await expect(deletePageSpeedChecksByMonitorId("monitorId"))
+  .to.be.rejectedWith(Error, "test error");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckDeleteManyStub.rejects(err);
try {
await expect(deletePageSpeedChecksByMonitorId("monitorId"));
} catch (error) {
expect(error).to.exist;
expect(error).to.deep.equal(err);
}
});
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckDeleteManyStub.rejects(err);
await expect(deletePageSpeedChecksByMonitorId("monitorId"))
.to.be.rejectedWith(Error, "test error");
});

Comment on lines +35 to +44
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckSaveStub.rejects(err);
try {
await expect(createPageSpeedCheck(mockPageSpeedCheck));
} catch (error) {
expect(error).to.exist;
expect(error).to.deep.equal(err);
}
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Knees weak, arms heavy - we got an error handling issue! 🍝

The error handling test has a potential issue. The current implementation won't actually verify that the promise rejects:

-try {
-  await expect(createPageSpeedCheck(mockPageSpeedCheck));
-} catch (error) {
-  expect(error).to.exist;
-  expect(error).to.deep.equal(err);
-}
+await expect(createPageSpeedCheck(mockPageSpeedCheck))
+  .to.be.rejectedWith(Error, "test error");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckSaveStub.rejects(err);
try {
await expect(createPageSpeedCheck(mockPageSpeedCheck));
} catch (error) {
expect(error).to.exist;
expect(error).to.deep.equal(err);
}
});
it("should handle an error", async () => {
const err = new Error("test error");
pageSpeedCheckSaveStub.rejects(err);
await expect(createPageSpeedCheck(mockPageSpeedCheck))
.to.be.rejectedWith(Error, "test error");
});

Comment on lines +48 to +52
it("should return the number of deleted checks", async () => {
pageSpeedCheckDeleteManyStub.resolves(mockDeletedResult);
const result = await deletePageSpeedChecksByMonitorId("monitorId");
expect(result).to.deep.equal(mockDeletedResult.deletedCount);
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

There's vomit on his sweater already - we're missing assertion! 🍝

We should verify that deleteMany was called with the correct parameters:

 it("should return the number of deleted checks", async () => {
   pageSpeedCheckDeleteManyStub.resolves(mockDeletedResult);
   const result = await deletePageSpeedChecksByMonitorId("monitorId");
   expect(result).to.deep.equal(mockDeletedResult.deletedCount);
+  expect(pageSpeedCheckDeleteManyStub.calledWith({ monitorId: "monitorId" })).to.be.true;
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should return the number of deleted checks", async () => {
pageSpeedCheckDeleteManyStub.resolves(mockDeletedResult);
const result = await deletePageSpeedChecksByMonitorId("monitorId");
expect(result).to.deep.equal(mockDeletedResult.deletedCount);
});
it("should return the number of deleted checks", async () => {
pageSpeedCheckDeleteManyStub.resolves(mockDeletedResult);
const result = await deletePageSpeedChecksByMonitorId("monitorId");
expect(result).to.deep.equal(mockDeletedResult.deletedCount);
expect(pageSpeedCheckDeleteManyStub.calledWith({ monitorId: "monitorId" })).to.be.true;
});

@ajhollid ajhollid merged commit f4c2777 into develop Nov 14, 2024
3 checks passed
@ajhollid ajhollid deleted the feat/be/tests-pagespeed-check-module branch November 14, 2024 07:03
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