From 9945aa734940833417775f3d98db188fc96ee436 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Tue, 18 Feb 2025 14:48:35 +0530 Subject: [PATCH 01/24] Add API endpoint test cases Ensure all endpoints are behaving as expected and documented in the API documentation. --- ballerina/tests/test.bal | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 ballerina/tests/test.bal diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal new file mode 100644 index 0000000..8c6695e --- /dev/null +++ b/ballerina/tests/test.bal @@ -0,0 +1,79 @@ +import ballerina/http; +import ballerina/test; + +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 = 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 +} +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? { + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[appIdSigned32](); + // TODO: Is there a better way to check for a 404 error rather than checking for all 4xx errors? + test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); +} + +@test:Config { + enable: true, + dependsOn: [testDeleteSettings] +} +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 testGetSettings() returns error? { + ExternalSettings|http:Response settings = check hubSpotVideoConferrencing->/[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:Config { + enable: true, + dependsOn: [testGetSettings] +} +function testDeleteSettingsAgain() returns error? { + http:Response response = check hubSpotVideoConferrencing->/[appIdSigned32].delete(); + test:assertTrue(response.statusCode == 204, "Error deleting settings"); +} + + + From 887f0021aee750248601420185adb13c8eb091bf Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Tue, 18 Feb 2025 16:38:52 +0530 Subject: [PATCH 02/24] Add mock service implementation for client tests 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. --- ballerina/Dependencies.toml | 4 --- ballerina/tests/mock_service.bal | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 ballerina/tests/mock_service.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index b714327..3237bb6 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -263,9 +263,6 @@ dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} ] -modules = [ - {org = "ballerina", packageName = "os", moduleName = "os"} -] [[package]] org = "ballerina" @@ -327,7 +324,6 @@ name = "hubspot.crm.extensions.videoconferencing" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, - {org = "ballerina", name = "os"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal new file mode 100644 index 0000000..5aa6bdb --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -0,0 +1,49 @@ +// 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|http:ClientRequestError { + if appId == appIdSigned32 && meetingSettings.createMeetingUrl != "" { + return meetingSettings; + } else { + return error("Invalid appId or empty meeting settings", body = "", headers = {}, statusCode = 404); + } + } + + resource function put [int:Signed32 appId](@http:Payload ExternalSettings payload) returns ExternalSettings { + meetingSettings = payload; + return meetingSettings; + } + + resource function delete [int:Signed32 appId]() returns http:Response { + meetingSettings = { + createMeetingUrl: "" + }; + http:Response response = new(); + response.statusCode = 204; + response.server = "ballerina"; + return response; + } +} From 44ad69c24c199302e7b6cf43d01529b0c1900bd7 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Wed, 19 Feb 2025 11:52:30 +0530 Subject: [PATCH 03/24] Update and fix test cases for client testing. 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. --- ballerina/tests/test.bal | 64 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 8c6695e..14db35f 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -1,5 +1,7 @@ import ballerina/http; import ballerina/test; +import ballerina/io; +import ballerina/lang.runtime; configurable string hapikey = ?; configurable int appId = ?; @@ -37,14 +39,17 @@ function testDeleteSettings() returns error? { 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](); - // TODO: Is there a better way to check for a 404 error rather than checking for all 4xx errors? test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @test:Config { enable: true, - dependsOn: [testDeleteSettings] + dependsOn: [testGetEmptySettings] } function testPutSettings() returns error? { ExternalSettings payload = { @@ -54,11 +59,27 @@ function testPutSettings() returns error? { 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); + } ExternalSettings|http:Response settings = check hubSpotVideoConferrencing->/[appIdSigned32](); test:assertTrue(settings is ExternalSettings, "Type mismatch"); if (settings is ExternalSettings) { @@ -66,6 +87,45 @@ function testGetSettings() returns error? { } } +@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] From 7604f4b453b0e8f1731e20dccc7416a4aa376ef1 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Wed, 19 Feb 2025 12:06:17 +0530 Subject: [PATCH 04/24] Update and fix mock service for edge cases Add appId validation to the mock service. Fix correct responses for invalid appId. --- ballerina/tests/mock_service.bal | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 5aa6bdb..2697c03 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -24,7 +24,7 @@ ExternalSettings meetingSettings = { }; service on new http:Listener(9090) { - resource function get [int:Signed32 appId]() returns ExternalSettings|http:ClientRequestError { + resource function get [int:Signed32 appId]() returns ExternalSettings|error { if appId == appIdSigned32 && meetingSettings.createMeetingUrl != "" { return meetingSettings; } else { @@ -32,12 +32,21 @@ service on new http:Listener(9090) { } } - resource function put [int:Signed32 appId](@http:Payload ExternalSettings payload) returns ExternalSettings { + resource function put [int:Signed32 appId](@http:Payload ExternalSettings payload) returns ExternalSettings|error { + if appId != appIdSigned32 { + return error("Invalid appId", body = "", headers = {}, statusCode = 400); + } meetingSettings = payload; return meetingSettings; } - resource function delete [int:Signed32 appId]() returns http:Response { + 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: "" }; From fc64160bcebd12c84c2c0371b4f127d5922d59e1 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Wed, 19 Feb 2025 12:18:11 +0530 Subject: [PATCH 05/24] Add updated Dependencies.toml --- ballerina/Dependencies.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 3237bb6..8b24ad4 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -108,6 +108,9 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} ] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] [[package]] org = "ballerina" @@ -194,6 +197,9 @@ version = "0.0.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"} +] [[package]] org = "ballerina" @@ -324,6 +330,8 @@ name = "hubspot.crm.extensions.videoconferencing" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "lang.runtime"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} From 2a280bf4625b6f8306572f7854f1bc0306842cca Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:22:27 +0530 Subject: [PATCH 06/24] Update the license header in mock_service.bal file Remove the auto-generated comment from mock_service.bal file. --- ballerina/tests/mock_service.bal | 3 --- 1 file changed, 3 deletions(-) diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 2697c03..441b44d 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -1,6 +1,3 @@ -// 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, From 4ab1e055a6e98fe40c4d264c7894ab848140eed0 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:31:35 +0530 Subject: [PATCH 07/24] Fix extra parentheses in test.bal Remove additional parentheses in if conditions in test.bal --- ballerina/tests/test.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 14db35f..b76b4f4 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -82,7 +82,7 @@ function testGetSettings() returns error? { } ExternalSettings|http:Response settings = check hubSpotVideoConferrencing->/[appIdSigned32](); test:assertTrue(settings is ExternalSettings, "Type mismatch"); - if (settings is ExternalSettings) { + if settings is ExternalSettings { test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error getting settings"); } } From 8313a8b34001589bf0ee44072da7b7e28763e7c7 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:36:37 +0530 Subject: [PATCH 08/24] Fix spelling mistakes in test.bal --- ballerina/tests/test.bal | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index b76b4f4..74dc67e 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -12,7 +12,7 @@ configurable boolean isLiveServer = true; final int:Signed32 appIdSigned32 = appId; final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; -final Client hubSpotVideoConferrencing = check initClient(); +final Client hubSpotVideoConferencing = check initClient(); isolated function initClient() returns Client|error { if isLiveServer { @@ -30,7 +30,7 @@ isolated function initClient() returns Client|error { enable: true } function testDeleteSettings() returns error? { - http:Response response = check hubSpotVideoConferrencing->/[appIdSigned32].delete(); + http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); test:assertTrue(response.statusCode == 204, "Error deleting settings"); } @@ -43,7 +43,7 @@ function testGetEmptySettings() returns error? { // Wait for the server to be updated the settings runtime:sleep(60); } - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[appIdSigned32](); + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[appIdSigned32](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -55,7 +55,7 @@ function testPutSettings() returns error? { ExternalSettings payload = { createMeetingUrl: "https://example.com/create-meeting" }; - ExternalSettings settings = check hubSpotVideoConferrencing->/[appIdSigned32].put(payload); + ExternalSettings settings = check hubSpotVideoConferencing->/[appIdSigned32].put(payload); test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting settings"); } @@ -67,7 +67,7 @@ function testPutIncorrectAppId() returns error? { ExternalSettings payload = { createMeetingUrl: "https://example.com/create-meeting" }; - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[1234].put(payload); + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[1234].put(payload); test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); } @@ -80,7 +80,7 @@ function testGetSettings() returns error? { // Wait for the server to be updated the settings runtime:sleep(60); } - ExternalSettings|http:Response settings = check hubSpotVideoConferrencing->/[appIdSigned32](); + 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"); @@ -92,7 +92,7 @@ function testGetSettings() returns error? { dependsOn: [testPutSettings] } function testGetIncorrectAppId() returns error? { - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferrencing->/[1234](); + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[1234](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -101,7 +101,7 @@ function testGetIncorrectAppId() returns error? { dependsOn: [testGetSettings] } function testDeleteIncorrectAppId() returns error? { - http:Response response = check hubSpotVideoConferrencing->/[1234].delete(); + http:Response response = check hubSpotVideoConferencing->/[1234].delete(); io:println(typeof(response)); test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); } @@ -118,7 +118,7 @@ function testPutCompeteSettings() returns error? { userVerifyUrl: "https://example.com/verify-user", fetchAccountsUri: "https://example.com/fetch-accounts" }; - ExternalSettings settings = check hubSpotVideoConferrencing->/[appIdSigned32].put(payload); + 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"); @@ -131,7 +131,7 @@ function testPutCompeteSettings() returns error? { dependsOn: [testGetSettings] } function testDeleteSettingsAgain() returns error? { - http:Response response = check hubSpotVideoConferrencing->/[appIdSigned32].delete(); + http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); test:assertTrue(response.statusCode == 204, "Error deleting settings"); } From b46d0a5167486bc50d74c30c3cd8366827a40e4f Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:38:19 +0530 Subject: [PATCH 09/24] Remove debug print statement from test.bal Print statement used for checking the type of a response was removed as it is not needed anymore. --- ballerina/tests/test.bal | 2 -- 1 file changed, 2 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 74dc67e..32a5fd6 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -1,6 +1,5 @@ import ballerina/http; import ballerina/test; -import ballerina/io; import ballerina/lang.runtime; configurable string hapikey = ?; @@ -102,7 +101,6 @@ function testGetIncorrectAppId() returns error? { } function testDeleteIncorrectAppId() returns error? { http:Response response = check hubSpotVideoConferencing->/[1234].delete(); - io:println(typeof(response)); test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); } From 7095ee86dd9e16d889af45a5dda293d1655407f0 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:45:57 +0530 Subject: [PATCH 10/24] Add license header to test.bal --- ballerina/tests/test.bal | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 32a5fd6..ace59cf 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -1,3 +1,19 @@ +// 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; import ballerina/lang.runtime; From 7ebc30eb13305b9f897d874ccb603a09d59e907f Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:49:16 +0530 Subject: [PATCH 11/24] Bal format the entire module --- ballerina/client.bal | 3 ++- ballerina/tests/mock_service.bal | 8 ++++---- ballerina/tests/test.bal | 8 +++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ballerina/client.bal b/ballerina/client.bal index 22962c7..a45272e 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -7,13 +7,14 @@ import ballerina/http; public isolated client class Client { final http:Client clientEp; final readonly & ApiKeysConfig apiKeyConfig; + # Gets invoked to initialize the `connector`. # # + apiKeyConfig - API keys for authorization # + config - The configurations to be used when initializing the `connector` # + serviceUrl - URL of the target service # + return - An error if connector initialization failed - public isolated function init(ApiKeysConfig apiKeyConfig, ConnectionConfig config = {}, string serviceUrl = "https://api.hubapi.com/crm/v3/extensions/videoconferencing/settings") returns error? { + public isolated function init(ApiKeysConfig apiKeyConfig, ConnectionConfig config = {}, string serviceUrl = "https://api.hubapi.com/crm/v3/extensions/videoconferencing/settings") returns error? { http:ClientConfiguration httpClientConfig = {httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; do { if config.http1Settings is ClientHttp1Settings { diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 441b44d..661816e 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -25,13 +25,13 @@ service on new http:Listener(9090) { if appId == appIdSigned32 && meetingSettings.createMeetingUrl != "" { return meetingSettings; } else { - return error("Invalid appId or empty meeting settings", body = "", headers = {}, statusCode = 404); + return 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 error("Invalid appId", body = "", headers = {}, statusCode = 400); + return error("Invalid appId", body = "", headers = {}, statusCode = 400); } meetingSettings = payload; return meetingSettings; @@ -39,7 +39,7 @@ service on new http:Listener(9090) { resource function delete [int:Signed32 appId]() returns http:Response|error { if appId != appIdSigned32 { - http:Response response = new(); + http:Response response = new (); response.statusCode = 404; response.server = "ballerina"; return response; @@ -47,7 +47,7 @@ service on new http:Listener(9090) { meetingSettings = { createMeetingUrl: "" }; - http:Response response = new(); + http:Response response = new (); response.statusCode = 204; response.server = "ballerina"; return response; diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index ace59cf..c2bab52 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -15,8 +15,8 @@ // under the License. import ballerina/http; -import ballerina/test; import ballerina/lang.runtime; +import ballerina/test; configurable string hapikey = ?; configurable int appId = ?; @@ -25,7 +25,7 @@ configurable string liveServerUrl = "https://api.hubapi.com/crm/v3/extensions/vi configurable string localServerUrl = "http://localhost:9090"; configurable boolean isLiveServer = true; -final int:Signed32 appIdSigned32 = appId; +final int:Signed32 appIdSigned32 = appId; final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; final Client hubSpotVideoConferencing = check initClient(); @@ -43,7 +43,7 @@ isolated function initClient() returns Client|error { @test:Config { enable: true -} +} function testDeleteSettings() returns error? { http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); test:assertTrue(response.statusCode == 204, "Error deleting settings"); @@ -149,5 +149,3 @@ function testDeleteSettingsAgain() returns error? { test:assertTrue(response.statusCode == 204, "Error deleting settings"); } - - From 47f6f2b7c7a65ed6a8ce40c7608ce402bd86883f Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 09:55:41 +0530 Subject: [PATCH 12/24] Add missing license for client, types, utils files --- ballerina/client.bal | 16 ++++++++++++++++ ballerina/types.bal | 18 +++++++++++++++++- ballerina/utils.bal | 18 +++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ballerina/client.bal b/ballerina/client.bal index a45272e..0991077 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -1,6 +1,22 @@ // 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; # These APIs allow you to specify URLs that can be used to interact with a video conferencing application, to allow HubSpot to add video conference links to meeting requests with contacts. diff --git a/ballerina/types.bal b/ballerina/types.bal index da92165..ba7134d 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1,6 +1,22 @@ -// AUTO-GENERATED FILE. +// 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; # The URLs of the various actions provided by the video conferencing application. All URLs must use the `https` protocol. diff --git a/ballerina/utils.bal b/ballerina/utils.bal index e470e3e..8269f00 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -1,6 +1,22 @@ -// AUTO-GENERATED FILE. +// 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; import ballerina/url; From ac3f788e06dc3bb95adeb55f9a839ba70e7a9b3c Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 10:05:53 +0530 Subject: [PATCH 13/24] Add updated Dependencies.toml file --- ballerina/Dependencies.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 8b24ad4..c6da4f5 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -70,7 +70,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.13.2" +version = "2.13.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -108,9 +108,6 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} ] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] [[package]] org = "ballerina" @@ -330,7 +327,6 @@ name = "hubspot.crm.extensions.videoconferencing" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, {org = "ballerina", name = "lang.runtime"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, From 03bc6f3ea80edb182e9cd86c2e2b4a7b356af455 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Thu, 20 Feb 2025 16:37:15 +0530 Subject: [PATCH 14/24] Remove unnecessary test configurations Tests are enabled by default, hence remove the unnecessary enable configuration. --- ballerina/tests/test.bal | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index c2bab52..4e75765 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -41,16 +41,13 @@ isolated function initClient() returns Client|error { }, {}, serviceUrl); } -@test:Config { - enable: true -} +@test:Config {} function testDeleteSettings() returns error? { http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); test:assertTrue(response.statusCode == 204, "Error deleting settings"); } @test:Config { - enable: true, dependsOn: [testDeleteSettings] } function testGetEmptySettings() returns error? { @@ -63,7 +60,6 @@ function testGetEmptySettings() returns error? { } @test:Config { - enable: true, dependsOn: [testGetEmptySettings] } function testPutSettings() returns error? { @@ -75,7 +71,6 @@ function testPutSettings() returns error? { } @test:Config { - enable: true, dependsOn: [testPutSettings] } function testPutIncorrectAppId() returns error? { @@ -87,7 +82,6 @@ function testPutIncorrectAppId() returns error? { } @test:Config { - enable: true, dependsOn: [testPutSettings] } function testGetSettings() returns error? { @@ -103,7 +97,6 @@ function testGetSettings() returns error? { } @test:Config { - enable: true, dependsOn: [testPutSettings] } function testGetIncorrectAppId() returns error? { @@ -112,7 +105,6 @@ function testGetIncorrectAppId() returns error? { } @test:Config { - enable: true, dependsOn: [testGetSettings] } function testDeleteIncorrectAppId() returns error? { @@ -121,7 +113,6 @@ function testDeleteIncorrectAppId() returns error? { } @test:Config { - enable: true, dependsOn: [testPutSettings] } function testPutCompeteSettings() returns error? { @@ -141,7 +132,6 @@ function testPutCompeteSettings() returns error? { } @test:Config { - enable: true, dependsOn: [testGetSettings] } function testDeleteSettingsAgain() returns error? { From 40223572016a510831e2df095c29922cc7a0e263 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Fri, 21 Feb 2025 14:42:11 +0530 Subject: [PATCH 15/24] Remove delay in live tests for get method 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. --- ballerina/tests/test.bal | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 4e75765..776f21f 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -51,10 +51,6 @@ function testDeleteSettings() returns error? { 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 = hubSpotVideoConferencing->/[appIdSigned32](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -85,10 +81,6 @@ function testPutIncorrectAppId() returns error? { dependsOn: [testPutSettings] } function testGetSettings() returns error? { - if isLiveServer { - // Wait for the server to be updated the settings - runtime:sleep(60); - } ExternalSettings|http:Response settings = check hubSpotVideoConferencing->/[appIdSigned32](); test:assertTrue(settings is ExternalSettings, "Type mismatch"); if settings is ExternalSettings { From f55efa7efdfd527169eafa4e2d13adb956812379 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Fri, 21 Feb 2025 15:02:25 +0530 Subject: [PATCH 16/24] Add test case descriptions Add concise test case descriptions with stating the positive or negative scenario. --- ballerina/tests/test.bal | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 776f21f..f3268ce 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -41,12 +41,14 @@ isolated function initClient() returns Client|error { }, {}, serviceUrl); } +// Test: Delete existing settings if any (Positive) @test:Config {} function testDeleteSettings() returns error? { http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); test:assertTrue(response.statusCode == 204, "Error deleting settings"); } +// Test: Get settings when no settings are available (Negative) @test:Config { dependsOn: [testDeleteSettings] } @@ -55,6 +57,7 @@ function testGetEmptySettings() returns error? { test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } +// Test: Put partial settings (Positive) @test:Config { dependsOn: [testGetEmptySettings] } @@ -66,6 +69,7 @@ function testPutSettings() returns error? { test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting settings"); } +// Test: Put settings with incorrect appId (Negative) @test:Config { dependsOn: [testPutSettings] } @@ -77,6 +81,7 @@ function testPutIncorrectAppId() returns error? { test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); } +// Test: Get settings (Positive) @test:Config { dependsOn: [testPutSettings] } @@ -88,6 +93,7 @@ function testGetSettings() returns error? { } } +// Test: Delete settings (Positive) @test:Config { dependsOn: [testPutSettings] } @@ -96,6 +102,7 @@ function testGetIncorrectAppId() returns error? { test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } +// Test: Delete settings with incorrect appId (Negative) @test:Config { dependsOn: [testGetSettings] } @@ -104,6 +111,7 @@ function testDeleteIncorrectAppId() returns error? { test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); } +// Test: Put complete settings (Positive) @test:Config { dependsOn: [testPutSettings] } @@ -123,6 +131,7 @@ function testPutCompeteSettings() returns error? { test:assertEquals(settings?.fetchAccountsUri, "https://example.com/fetch-accounts", "Error putting complete settings"); } +// Test: Delete complete settings (Positive) @test:Config { dependsOn: [testGetSettings] } From 8ece220af0900d1db00c507ff4d3da63802dbf15 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Fri, 21 Feb 2025 15:06:06 +0530 Subject: [PATCH 17/24] Remove unused import ballerina/lang.runtime Previously used for delaying the live server test cases for get requests. Since the delay was removed, this import is no longer needed. --- ballerina/tests/test.bal | 1 - 1 file changed, 1 deletion(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index f3268ce..a7c08c6 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -15,7 +15,6 @@ // under the License. import ballerina/http; -import ballerina/lang.runtime; import ballerina/test; configurable string hapikey = ?; From 2fbb920c25223a41f7005f10599d9833ebb604b6 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Fri, 21 Feb 2025 15:06:06 +0530 Subject: [PATCH 18/24] Remove unused import ballerina/lang.runtime Previously used for delaying the live server test cases for get requests. Since the delay was removed, this import is no longer needed. --- ballerina/Dependencies.toml | 4 ---- ballerina/tests/test.bal | 1 - 2 files changed, 5 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c6da4f5..c78b64a 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -194,9 +194,6 @@ version = "0.0.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] -modules = [ - {org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"} -] [[package]] org = "ballerina" @@ -327,7 +324,6 @@ name = "hubspot.crm.extensions.videoconferencing" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, - {org = "ballerina", name = "lang.runtime"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index f3268ce..a7c08c6 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -15,7 +15,6 @@ // under the License. import ballerina/http; -import ballerina/lang.runtime; import ballerina/test; configurable string hapikey = ?; From 2ebddb474d02db766cfb2f23225e43ffca452ebc Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Mon, 24 Feb 2025 11:28:39 +0530 Subject: [PATCH 19/24] Fix improper use of assertTrue in test.bal Use assertEquals instead of assertTrue to compare the actual and expected values when checking for the response code. --- ballerina/tests/test.bal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index a7c08c6..faee0a1 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -22,7 +22,7 @@ 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; +configurable boolean isLiveServer = false; final int:Signed32 appIdSigned32 = appId; final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; @@ -44,7 +44,7 @@ isolated function initClient() returns Client|error { @test:Config {} function testDeleteSettings() returns error? { http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); - test:assertTrue(response.statusCode == 204, "Error deleting settings"); + test:assertEquals(response.statusCode, 204, "Error deleting settings"); } // Test: Get settings when no settings are available (Negative) @@ -136,6 +136,6 @@ function testPutCompeteSettings() returns error? { } function testDeleteSettingsAgain() returns error? { http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); - test:assertTrue(response.statusCode == 204, "Error deleting settings"); + test:assertEquals(response.statusCode, 204, "Error deleting settings"); } From 418d81d461d839964d7ce28f0378ccade25a0551 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Mon, 24 Feb 2025 11:35:33 +0530 Subject: [PATCH 20/24] Use final variables for incorrectAppId in test.bal Instead of hard-coded incorrectAppId in the request URL, use a final variable for better readability and maintainability. --- ballerina/tests/test.bal | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index faee0a1..931cc1a 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -25,6 +25,7 @@ configurable string localServerUrl = "http://localhost:9090"; configurable boolean isLiveServer = false; final int:Signed32 appIdSigned32 = appId; +final int:Signed32 incorrectAppId = 1234; final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; final Client hubSpotVideoConferencing = check initClient(); @@ -76,7 +77,7 @@ function testPutIncorrectAppId() returns error? { ExternalSettings payload = { createMeetingUrl: "https://example.com/create-meeting" }; - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[1234].put(payload); + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId].put(payload); test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); } @@ -97,7 +98,7 @@ function testGetSettings() returns error? { dependsOn: [testPutSettings] } function testGetIncorrectAppId() returns error? { - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[1234](); + ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -106,7 +107,7 @@ function testGetIncorrectAppId() returns error? { dependsOn: [testGetSettings] } function testDeleteIncorrectAppId() returns error? { - http:Response response = check hubSpotVideoConferencing->/[1234].delete(); + http:Response response = check hubSpotVideoConferencing->/[incorrectAppId].delete(); test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); } From 972f217a0bde986cd182e3cb35effec5e2ac75cd Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Mon, 24 Feb 2025 15:04:03 +0530 Subject: [PATCH 21/24] Move all configurable values to Config.toml With this change, configurable variable values can change without needing a recompilation of the source code. --- ballerina/tests/test.bal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 931cc1a..067e994 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -20,9 +20,9 @@ import ballerina/test; 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 = false; +configurable string liveServerUrl = ?; +configurable string localServerUrl = ?; +configurable boolean isLiveServer = ?; final int:Signed32 appIdSigned32 = appId; final int:Signed32 incorrectAppId = 1234; From 470dfc74424c7620745202e01398659480ca4fdd Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Mon, 24 Feb 2025 17:42:20 +0530 Subject: [PATCH 22/24] Add defaults for configurable variables in test.bal --- ballerina/tests/test.bal | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 067e994..d060858 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -17,12 +17,12 @@ import ballerina/http; import ballerina/test; -configurable string hapikey = ?; -configurable int appId = ?; +configurable string hapikey = "my-key-123"; +configurable int appId = 12345; -configurable string liveServerUrl = ?; -configurable string localServerUrl = ?; -configurable boolean isLiveServer = ?; +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 = appId; final int:Signed32 incorrectAppId = 1234; From 9b18f46a0fa83981e274e2082b62dfc3f7e008a0 Mon Sep 17 00:00:00 2001 From: Ravindu Weerasinghe Date: Mon, 24 Feb 2025 17:44:34 +0530 Subject: [PATCH 23/24] Rename client to a simpler name Instead of lengthy name `hubSpotVideoConferencing` for the client, use the simpler name `hubspot`. --- ballerina/tests/test.bal | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index d060858..47684a8 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -27,7 +27,7 @@ configurable boolean isLiveServer = true; final int:Signed32 appIdSigned32 = appId; final int:Signed32 incorrectAppId = 1234; final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; -final Client hubSpotVideoConferencing = check initClient(); +final Client hubspot = check initClient(); isolated function initClient() returns Client|error { if isLiveServer { @@ -44,7 +44,7 @@ isolated function initClient() returns Client|error { // Test: Delete existing settings if any (Positive) @test:Config {} function testDeleteSettings() returns error? { - http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); + http:Response response = check hubspot->/[appIdSigned32].delete(); test:assertEquals(response.statusCode, 204, "Error deleting settings"); } @@ -53,7 +53,7 @@ function testDeleteSettings() returns error? { dependsOn: [testDeleteSettings] } function testGetEmptySettings() returns error? { - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[appIdSigned32](); + ExternalSettings|http:ClientRequestError|error settings = hubspot->/[appIdSigned32](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -65,7 +65,7 @@ function testPutSettings() returns error? { ExternalSettings payload = { createMeetingUrl: "https://example.com/create-meeting" }; - ExternalSettings settings = check hubSpotVideoConferencing->/[appIdSigned32].put(payload); + ExternalSettings settings = check hubspot->/[appIdSigned32].put(payload); test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error putting settings"); } @@ -77,7 +77,7 @@ function testPutIncorrectAppId() returns error? { ExternalSettings payload = { createMeetingUrl: "https://example.com/create-meeting" }; - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId].put(payload); + ExternalSettings|http:ClientRequestError|error settings = hubspot->/[incorrectAppId].put(payload); test:assertTrue(settings is http:ClientRequestError, "Error putting settings with incorrect appId"); } @@ -86,7 +86,7 @@ function testPutIncorrectAppId() returns error? { dependsOn: [testPutSettings] } function testGetSettings() returns error? { - ExternalSettings|http:Response settings = check hubSpotVideoConferencing->/[appIdSigned32](); + ExternalSettings|http:Response settings = check hubspot->/[appIdSigned32](); test:assertTrue(settings is ExternalSettings, "Type mismatch"); if settings is ExternalSettings { test:assertEquals(settings.createMeetingUrl, "https://example.com/create-meeting", "Error getting settings"); @@ -98,7 +98,7 @@ function testGetSettings() returns error? { dependsOn: [testPutSettings] } function testGetIncorrectAppId() returns error? { - ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[incorrectAppId](); + ExternalSettings|http:ClientRequestError|error settings = hubspot->/[incorrectAppId](); test:assertTrue(settings is http:ClientRequestError, "Error getting settings"); } @@ -107,7 +107,7 @@ function testGetIncorrectAppId() returns error? { dependsOn: [testGetSettings] } function testDeleteIncorrectAppId() returns error? { - http:Response response = check hubSpotVideoConferencing->/[incorrectAppId].delete(); + http:Response response = check hubspot->/[incorrectAppId].delete(); test:assertEquals(response.statusCode, 404, "Error deleting settings with incorrect appId"); } @@ -123,7 +123,7 @@ function testPutCompeteSettings() returns error? { userVerifyUrl: "https://example.com/verify-user", fetchAccountsUri: "https://example.com/fetch-accounts" }; - ExternalSettings settings = check hubSpotVideoConferencing->/[appIdSigned32].put(payload); + ExternalSettings settings = check hubspot->/[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"); @@ -136,7 +136,7 @@ function testPutCompeteSettings() returns error? { dependsOn: [testGetSettings] } function testDeleteSettingsAgain() returns error? { - http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete(); + http:Response response = check hubspot->/[appIdSigned32].delete(); test:assertEquals(response.statusCode, 204, "Error deleting settings"); } From 631953156b8749512c787fe18aedba509b0e33a7 Mon Sep 17 00:00:00 2001 From: Nuvindu Nirmana <63797478+Nuvindu@users.noreply.github.com> Date: Mon, 24 Feb 2025 18:09:39 +0530 Subject: [PATCH 24/24] Update variable to check for a live server --- ballerina/tests/test.bal | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 47684a8..ae4a136 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -16,13 +16,14 @@ import ballerina/http; import ballerina/test; +import ballerina/os; 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; +configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; final int:Signed32 appIdSigned32 = appId; final int:Signed32 incorrectAppId = 1234;