Skip to content

Comments

Add API test cases and implement mock service#4

Merged
Nuvindu merged 32 commits intoballerina-platform:mainfrom
rtweera:main
Feb 24, 2025
Merged

Add API test cases and implement mock service#4
Nuvindu merged 32 commits intoballerina-platform:mainfrom
rtweera:main

Conversation

@rtweera
Copy link
Contributor

@rtweera rtweera commented Feb 19, 2025

Purpose

This PR adds test cases for API endpoints along with a mock service to simulate responses during testing. The goal is to ensure the API behaves as expected under various conditions, improving overall reliability and test coverage.

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

rtweera and others added 6 commits February 18, 2025 14:48
Ensure all endpoints are behaving as expected and documented in the API
documentation.
Add mock service for quick testing of the client.bal. This mock service
removes the server side dependency for the test cases and ensures they
run in a consistant manner.
Update positive and negative test cases for the client to handle certain
edge cases. This includes tests for invalid app id and payload with
complete settings (i.e. including all optionals).

Fix the test cases to deal with the DB delay happening at HubSpot's end.
HubSpot requires a delay around a minute to update the settings in the
DB. Test cases with method GET fails due to this delay, if it is not
accounted for.
Add appId validation to the mock service.
Fix correct responses for invalid appId.
Update tests with edge cases
rtweera and others added 9 commits February 20, 2025 09:22
Remove the auto-generated comment from mock_service.bal file.
Remove additional parentheses in if conditions in test.bal
Print statement used for checking the type of a response was removed
as it is not needed anymore.
Update with formatting fixes
rtweera and others added 7 commits February 20, 2025 16:37
Tests are enabled by default, hence remove the unnecessary enable
configuration.
Remove unnecessary test configurations
Adding a delay in the tests could cause intermittent failures if the
delay is not sufficient for the particular situation. This commit
removes the delay in the live tests for the get method.

This will result in couple of test failures in the live tests but consistent
test results are achieved.
Add concise test case descriptions with stating the positive or negative
scenario.
Previously used for delaying the live server test cases for get requests.
Since the delay was removed, this import is no longer needed.
Previously used for delaying the live server test cases for get requests.
Since the delay was removed, this import is no longer needed.
Remove delay in tests & Add test descriptions
rtweera and others added 3 commits February 24, 2025 11:28
Use assertEquals instead of assertTrue to compare the actual and
expected values when checking for the response code.
Instead of hard-coded incorrectAppId in the request URL, use a final
variable for better readability and maintainability.
Fix hardcoded value and incorrect use of assertTrue
rtweera and others added 2 commits February 24, 2025 15:04
With this change, configurable variable values can change without needing
a recompilation of the source code.
Move all configurable values to Config.toml
Comment on lines 20 to 25
configurable string hapikey = ?;
configurable int appId = ?;

configurable string liveServerUrl = ?;
configurable string localServerUrl = ?;
configurable boolean isLiveServer = ?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add default values for these configurable variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for liveServerUrl I added the actual url, instead of a dummy one. If it needs to be replaced to a dummy one, kindly let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add those default values in the file itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As in like this?

configurable string hapikey = "my-key-123";
configurable int appId = 12345;

configurable string liveServerUrl = "https://api.hubapi.com/crm/v3/extensions/videoconferencing/settings";
configurable string localServerUrl = "http://localhost:9090";
configurable boolean isLiveServer = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. As discussed in the meeting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sure

rtweera and others added 3 commits February 24, 2025 17:42
Instead of lengthy name `hubSpotVideoConferencing` for the client, use
the simpler name `hubspot`.
Add configurable defaults and rename client
@Nuvindu Nuvindu merged commit 7f0af29 into ballerina-platform:main Feb 24, 2025
2 checks passed
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