-
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
Changes from 28 commits
9945aa7
887f002
44ad69c
7604f4b
fc64160
88304e9
2a280bf
4ab1e05
8313a8b
b46d0a5
7095ee8
7ebc30e
47f6f2b
ac3f788
20a198c
03bc6f3
7318152
4022357
f55efa7
8ece220
2fbb920
9b08541
488ce6d
2ebddb4
418d81d
2dc3804
972f217
856504f
470dfc7
9b18f46
a9d714a
6319531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // 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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // 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; | ||
| import ballerina/test; | ||
|
|
||
| configurable string hapikey = ?; | ||
| configurable int appId = ?; | ||
|
|
||
| configurable string liveServerUrl = ?; | ||
| configurable string localServerUrl = ?; | ||
| configurable boolean isLiveServer = ?; | ||
|
||
|
|
||
| final int:Signed32 appIdSigned32 = <int:Signed32>appId; | ||
| final int:Signed32 incorrectAppId = 1234; | ||
| final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; | ||
| final Client hubSpotVideoConferencing = check initClient(); | ||
rtweera marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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: Delete existing settings if any (Positive) | ||
| @test:Config {} | ||
| function testDeleteSettings() returns error? { | ||
| http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); | ||
| test:assertEquals(response.statusCode, 204, "Error deleting settings"); | ||
| } | ||
|
|
||
| // Test: Get settings when no settings are available (Negative) | ||
| @test:Config { | ||
| dependsOn: [testDeleteSettings] | ||
| } | ||
| function testGetEmptySettings() returns error? { | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[appIdSigned32](); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); | ||
| } | ||
|
|
||
| // Test: Put partial settings (Positive) | ||
| @test:Config { | ||
| dependsOn: [testGetEmptySettings] | ||
| } | ||
| function testPutSettings() returns error? { | ||
| ExternalSettings payload = { | ||
| createMeetingUrl: "https://example.com/create-meeting" | ||
| }; | ||
| ExternalSettings settings = check hubSpotVideoConferencing->/[appIdSigned32].put(payload); | ||
| test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting settings"); | ||
| } | ||
|
|
||
| // Test: Put settings with incorrect appId (Negative) | ||
| @test:Config { | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testPutIncorrectAppId() returns error? { | ||
| ExternalSettings payload = { | ||
| createMeetingUrl: "https://example.com/create-meeting" | ||
| }; | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId].put(payload); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); | ||
| } | ||
|
|
||
| // Test: Get settings (Positive) | ||
| @test:Config { | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testGetSettings() returns error? { | ||
| ExternalSettings|http:Response settings = check hubSpotVideoConferencing->/[appIdSigned32](); | ||
| test:assertTrue(settings is ExternalSettings, "Type mismatch"); | ||
| if settings is ExternalSettings { | ||
| test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error getting settings"); | ||
| } | ||
| } | ||
|
|
||
| // Test: Delete settings (Positive) | ||
| @test:Config { | ||
| dependsOn: [testPutSettings] | ||
| } | ||
| function testGetIncorrectAppId() returns error? { | ||
| ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId](); | ||
| test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); | ||
| } | ||
|
|
||
| // Test: Delete settings with incorrect appId (Negative) | ||
| @test:Config { | ||
| dependsOn: [testGetSettings] | ||
| } | ||
| function testDeleteIncorrectAppId() returns error? { | ||
| http:Response response = check hubSpotVideoConferencing->/[incorrectAppId].delete(); | ||
| test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); | ||
| } | ||
|
|
||
| // Test: Put complete settings (Positive) | ||
| @test:Config { | ||
| 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 hubSpotVideoConferencing->/[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: Delete complete settings (Positive) | ||
| @test:Config { | ||
| dependsOn: [testGetSettings] | ||
| } | ||
| function testDeleteSettingsAgain() returns error? { | ||
| http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); | ||
| test:assertEquals(response.statusCode, 204, "Error deleting settings"); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.