-
Notifications
You must be signed in to change notification settings - Fork 2
Add API test cases and implement mock service #4
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9945aa7
Add API endpoint test cases
rtweera 887f002
Add mock service implementation for client tests
rtweera 44ad69c
Update and fix test cases for client testing.
rtweera 7604f4b
Update and fix mock service for edge cases
rtweera fc64160
Add updated Dependencies.toml
rtweera 88304e9
Merge pull request #4 from rtweera/test
rtweera 2a280bf
Update the license header in mock_service.bal file
rtweera 4ab1e05
Fix extra parentheses in test.bal
rtweera 8313a8b
Fix spelling mistakes in test.bal
rtweera b46d0a5
Remove debug print statement from test.bal
rtweera 7095ee8
Add license header to test.bal
rtweera 7ebc30e
Bal format the entire module
rtweera 47f6f2b
Add missing license for client, types, utils files
rtweera ac3f788
Add updated Dependencies.toml file
rtweera 20a198c
Merge pull request #5 from rtweera/test
rtweera 03bc6f3
Remove unnecessary test configurations
rtweera 7318152
Merge pull request #6 from rtweera/test
rtweera 4022357
Remove delay in live tests for get method
rtweera f55efa7
Add test case descriptions
rtweera 8ece220
Remove unused import ballerina/lang.runtime
rtweera 2fbb920
Remove unused import ballerina/lang.runtime
rtweera 9b08541
Merge branch origin test into test
rtweera 488ce6d
Merge pull request #7 from rtweera/test
rtweera 2ebddb4
Fix improper use of assertTrue in test.bal
rtweera 418d81d
Use final variables for incorrectAppId in test.bal
rtweera 2dc3804
Merge pull request #8 from rtweera/test
rtweera 972f217
Move all configurable values to Config.toml
rtweera 856504f
Merge pull request #9 from rtweera/test
rtweera 470dfc7
Add defaults for configurable variables in test.bal
rtweera 9b18f46
Rename client to a simpler name
rtweera a9d714a
Merge pull request #10 from rtweera/test
rtweera 6319531
Update variable to check for a live server
Nuvindu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // AUTO-GENERATED FILE. DO NOT MODIFY. | ||
| // This file is auto-generated by the Ballerina OpenAPI tool. | ||
|
|
||
| // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import ballerina/http; | ||
|
|
||
| ExternalSettings meetingSettings = { | ||
| createMeetingUrl: "" | ||
| }; | ||
|
|
||
| service on new http:Listener(9090) { | ||
| resource function get [int:Signed32 appId]() returns ExternalSettings|error { | ||
| if appId == appIdSigned32 && meetingSettings.createMeetingUrl != "" { | ||
| return meetingSettings; | ||
| } else { | ||
| return <http:ClientRequestError> error("Invalid appId or empty meeting settings", body = "", headers = {}, statusCode = 404); | ||
| } | ||
| } | ||
|
|
||
| resource function put [int:Signed32 appId](@http:Payload ExternalSettings payload) returns ExternalSettings|error { | ||
| if appId != appIdSigned32 { | ||
| return <http:ClientRequestError> error("Invalid appId", body = "", headers = {}, statusCode = 400); | ||
| } | ||
| meetingSettings = payload; | ||
| return meetingSettings; | ||
| } | ||
|
|
||
| resource function delete [int:Signed32 appId]() returns http:Response|error { | ||
| if appId != appIdSigned32 { | ||
| http:Response response = new(); | ||
| response.statusCode = 404; | ||
| response.server = "ballerina"; | ||
| return response; | ||
| } | ||
| meetingSettings = { | ||
| createMeetingUrl: "" | ||
| }; | ||
| http:Response response = new(); | ||
| response.statusCode = 204; | ||
| response.server = "ballerina"; | ||
| return response; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import ballerina/http; | ||
rtweera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import ballerina/test; | ||
| import ballerina/io; | ||
| import ballerina/lang.runtime; | ||
|
|
||
| configurable string hapikey = ?; | ||
| configurable int appId = ?; | ||
|
|
||
| configurable string liveServerUrl = "https://api.hubapi.com/crm/v3/extensions/videoconferencing/settings"; | ||
| configurable string localServerUrl = "http://localhost:9090"; | ||
| configurable boolean isLiveServer = true; | ||
|
|
||
| final int:Signed32 appIdSigned32 = <int:Signed32> appId; | ||
| final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; | ||
| final Client hubSpotVideoConferrencing = check initClient(); | ||
|
|
||
| isolated function initClient() returns Client|error { | ||
| if isLiveServer { | ||
| final ApiKeysConfig apiKeysConfig = { | ||
| hapikey: hapikey | ||
| }; | ||
| return check new (apiKeysConfig, {}, serviceUrl); | ||
| } | ||
| return check new ({ | ||
| hapikey: hapikey | ||
| }, {}, serviceUrl); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true | ||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| function testDeleteSettings() returns error? { | ||
| http:Response response = check hubSpotVideoConferrencing->/[appIdSigned32].delete(); | ||
| test:assertTrue(response.statusCode == 204, "Error deleting settings"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testDeleteSettings] | ||
| } | ||
| function testGetEmptySettings() returns error? { | ||
| if isLiveServer { | ||
| // Wait for the server to be updated the settings | ||
| runtime:sleep(60); | ||
| } | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[appIdSigned32](); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testGetEmptySettings] | ||
| } | ||
| function testPutSettings() returns error? { | ||
| ExternalSettings payload = { | ||
| createMeetingUrl: "https://example.com/create-meeting" | ||
| }; | ||
| ExternalSettings settings = check hubSpotVideoConferrencing->/[appIdSigned32].put(payload); | ||
| test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting settings"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testPutIncorrectAppId() returns error? { | ||
| ExternalSettings payload = { | ||
| createMeetingUrl: "https://example.com/create-meeting" | ||
| }; | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[1234].put(payload); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testGetSettings() returns error? { | ||
| if isLiveServer { | ||
| // Wait for the server to be updated the settings | ||
| runtime:sleep(60); | ||
| } | ||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExternalSettings|http:Response settings = check hubSpotVideoConferrencing->/[appIdSigned32](); | ||
| test:assertTrue(settings is ExternalSettings, "Type mismatch"); | ||
| if (settings is ExternalSettings) { | ||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error getting settings"); | ||
| } | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testGetIncorrectAppId() returns error? { | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[1234](); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testGetSettings] | ||
| } | ||
| function testDeleteIncorrectAppId() returns error? { | ||
| http:Response response = check hubSpotVideoConferrencing->/[1234].delete(); | ||
| io:println(typeof(response)); | ||
| test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testPutCompeteSettings() returns error? { | ||
| ExternalSettings payload = { | ||
| createMeetingUrl: "https://example.com/create-meeting", | ||
| updateMeetingUrl: "https://example.com/update-meeting", | ||
| deleteMeetingUrl: "https://example.com/delete-meeting", | ||
| userVerifyUrl: "https://example.com/verify-user", | ||
| fetchAccountsUri: "https://example.com/fetch-accounts" | ||
| }; | ||
| ExternalSettings settings = check hubSpotVideoConferrencing->/[appIdSigned32].put(payload); | ||
| test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting complete settings"); | ||
| test:assertEquals(settings?.updateMeetingUrl, "https://example.com/update-meeting", "Error putting complete settings"); | ||
| test:assertEquals(settings?.deleteMeetingUrl, "https://example.com/delete-meeting", "Error putting complete settings"); | ||
| test:assertEquals(settings?.userVerifyUrl, "https://example.com/verify-user", "Error putting complete settings"); | ||
| test:assertEquals(settings?.fetchAccountsUri, "https://example.com/fetch-accounts", "Error putting complete settings"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| enable: true, | ||
| dependsOn: [testGetSettings] | ||
| } | ||
| function testDeleteSettingsAgain() returns error? { | ||
| http:Response response = check hubSpotVideoConferrencing->/[appIdSigned32].delete(); | ||
| test:assertTrue(response.statusCode == 204, "Error deleting settings"); | ||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
||
|
|
||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.