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

Added Unit Test Cases for Wrapper and Helper Files #75

Merged
merged 14 commits into from
Aug 30, 2023

Conversation

Raj-Shah1
Copy link
Contributor

@Raj-Shah1 Raj-Shah1 commented Aug 29, 2023

Summary by CodeRabbit

  • Test: Added new unit tests for classes in the com.salessparrow.api.unit.lib.salesforce.helper and com.salessparrow.api.unit.lib.salesforce.wrappers packages. These tests cover methods related to Salesforce OAuth token management, HTTP request handling, and data retrieval from Salesforce.
  • Refactor: Improved existing test cases by adding more assertions and simulating different scenarios, enhancing the robustness of the test suite.

@coderabbitai
Copy link

coderabbitai bot commented Aug 29, 2023

Walkthrough

The changes introduce a suite of unit tests for various classes in the com.salessparrow.api.unit.lib.salesforce package. These tests cover methods responsible for making HTTP requests, handling Salesforce OAuth tokens, and interacting with Salesforce APIs. The tests use Mockito to mock dependencies and simulate different scenarios, ensuring that the methods behave as expected.

Changes

File Path Summary
.../lib/salesforce/helper/MakeCompositeRequestTest.java
.../lib/salesforce/helper/SalesforceOAuthTokenTest.java
.../lib/salesforce/helper/SalesforceRequestTest.java
New test classes added to verify the behavior of helper classes involved in making HTTP requests and handling Salesforce OAuth tokens.
.../lib/salesforce/wrappers/SalesforceGetIdentityTest.java
.../lib/salesforce/wrappers/SalesforceGetNoteContentTest.java
.../lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java
.../lib/salesforce/wrappers/SalesforceGetTokensTest.java
New test classes added to validate the functionality of wrapper classes that interact with various Salesforce APIs.

"In the land of code, where logic is king,

We test our functions, to make sure they sing 🎵.

With mocks and asserts, we set the stage,

Ensuring our software, is top of its age. 🐇"


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance. The bot stays silent unless called upon.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

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.

Review Status

Actionable comments generated: 8

Commits Files that changed from the base of the PR and between 729d590 and 03d36d4 commits.
Files selected for processing (7)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/MakeCompositeRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/MakeCompositeRequestTest.java
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java
Additional comments (Suppressed): 3
src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1)
  • 44-55: The test testFetchAccessToken is well written and covers the expected behavior of the fetchAccessToken method. It checks that the method correctly decrypts the access token.
src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java (2)
  • 40-65: The test testMakeRequest_Success is well written and covers the success scenario of the makeRequest method. It verifies that the correct methods are called with the expected parameters and that the response is as expected.

  • 95-123: The test testMakeRequest_InternalServerErrorException correctly simulates a server error by throwing a WebClientResponseException with a 500 status code. It also correctly verifies that the updateAndGetRefreshedAccessToken method is not called in this scenario. Good job on covering this edge case.

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.

Review Status

Actionable comments generated: 2

Commits Files that changed from the base of the PR and between 03d36d4 and d4cf003 commits.
Files selected for processing (5)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java (1 hunks)
Files skipped from review due to trivial changes (3)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java

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.

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between d4cf003 and 791a060 commits.
Files selected for processing (1)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1 hunks)
Additional comments (Suppressed): 1
src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1)
  • 44-55: The test testFetchAccessToken is well written and covers the expected behavior of the fetchAccessToken method. It verifies that the method correctly decrypts the access token.

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.

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 791a060 and 848c574 commits.
Files selected for processing (1)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (1 hunks)
Additional comments (Suppressed): 4
src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (4)
  • 1-79: The test cases are well written and cover both the successful scenario and the exception handling scenario. The use of Mockito to mock dependencies and simulate HTTP responses is a good practice. It ensures that the tests are not dependent on the actual Salesforce service, making them more reliable and faster to run.

  • 44-46: Ensure that the timeoutMillis method in SalesforceConstants returns an appropriate timeout value for your use case. If the timeout is too short, it might cause unnecessary failures when the Salesforce service is slow to respond. If it's too long, it might cause the tests to hang for a long time when there's a problem with the Salesforce service.

  • 48-49: This line mocks the makeRequest method in SalesforceRequest. Ensure that the second argument passed to this method (the SalesforceRequestInterface instance) is constructed correctly in the getNoteContent method. This is important because the makeRequest method will use this instance to construct the actual HTTP request sent to Salesforce.

  • 72-74: This line simulates an error by making the makeRequest method throw a RuntimeException. This is a good way to test how the getNoteContent method handles errors. However, ensure that the getNoteContent method is designed to handle this specific type of exception. If it's not, this test case might give you a false sense of security.

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.

Review Status

Actionable comments generated: 9

Commits Files that changed from the base of the PR and between 848c574 and 3eb44ea commits.
Files selected for processing (7)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/MakeCompositeRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/MakeCompositeRequestTest.java
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java
Additional comments (Suppressed): 1
src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1)
  • 44-55: The testFetchAccessToken() method is well implemented. It correctly mocks the necessary dependencies and asserts the expected outcome.

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.

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 3eb44ea and 472e8dd commits.
Files selected for processing (4)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetTokensTest.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetRefreshedAccessTokenTest.java
Additional comments (Suppressed): 3
src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (2)
  • 36-62: The test testGetUserIdentity_Success() is well written and covers the successful scenario of the getUserIdentity() method. It mocks the HttpClient's makeGetRequest() method, sets up expected headers, and verifies that the method was called with the correct arguments.

  • 64-97: The test testGetUserIdentity_Exception() effectively tests the exception handling in the getUserIdentity() method. It simulates a RuntimeException during the HTTP request and checks if it's correctly caught and wrapped into a CustomException with the expected error identifiers.

src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceOAuthTokenTest.java (1)
  • 46-56: The test testFetchAccessToken() is well written and covers the expected behavior of the fetchAccessToken() method. It correctly mocks the dependencies and verifies the result.

Copy link
Member

@AMAN-BARBARIA AMAN-BARBARIA left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Review Status

Actionable comments generated: 2

Commits Files that changed from the base of the PR and between 472e8dd and 80c938c commits.
Files selected for processing (4)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/helper/SalesforceRequestTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetNoteContentTest.java (1 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceTokensTest.java (3 hunks)
Additional comments (Suppressed): 3
src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceGetIdentityTest.java (1)
  • 1-99: The test cases for the getUserIdentity method in the SalesforceGetIdentity class are well written. They cover both the successful scenario and the exception handling scenario. The use of Mockito to mock the HttpClient's static method is a good practice, as it isolates the unit under test from external dependencies. The assertions are also correctly checking the expected outcomes.
src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceTokensTest.java (2)
  • 74-99: The testGetTokensSuccess() method tests the successful scenario of getting tokens. It sets up a mock static method call to HttpClient.makePostRequest(). The mock is configured to return a mock response when called with any arguments. The getTokens() method of the SalesforceTokens class is invoked with code and redirectUri parameters, and the expected response is compared with the actual response. This test ensures that the getTokens() method works as expected in the success scenario.

  • 101-132: The testGetTokensException() method tests the exception handling scenario of getting tokens. It sets up a mock static method call to HttpClient.makePostRequest(). The mock is configured to throw a RuntimeException when called with any arguments. The test asserts that invoking the getTokens() method with code and redirectUri parameters throws a CustomException. This test ensures that the getTokens() method correctly handles exceptions and throws a CustomException as expected.

@Raj-Shah1 Raj-Shah1 merged commit 3d7de4c into milestone/v0.2.0 Aug 30, 2023
@Raj-Shah1 Raj-Shah1 deleted the unit-testcase branch August 30, 2023 12:36
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