diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index b714327..c78b64a 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"}, @@ -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/client.bal b/ballerina/client.bal index 22962c7..0991077 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -1,19 +1,36 @@ // 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. 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 new file mode 100644 index 0000000..661816e --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -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 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); + } + 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; + } +} diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal new file mode 100644 index 0000000..ae4a136 --- /dev/null +++ b/ballerina/tests/test.bal @@ -0,0 +1,143 @@ +// 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/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 = os:getEnv("IS_LIVE_SERVER") == "true"; + +final int:Signed32 appIdSigned32 = appId; +final int:Signed32 incorrectAppId = 1234; +final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl; +final Client hubspot = 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: Delete existing settings if any (Positive) +@test:Config {} +function testDeleteSettings() returns error? { + http:Response response = check hubspot->/[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 = hubspot->/[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 hubspot->/[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 = hubspot->/[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 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"); + } +} + +// Test: Delete settings (Positive) +@test:Config { + dependsOn: [testPutSettings] +} +function testGetIncorrectAppId() returns error? { + ExternalSettings|http:ClientRequestError|error settings = hubspot->/[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 hubspot->/[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 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"); + 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 hubspot->/[appIdSigned32].delete(); + test:assertEquals(response.statusCode, 204, "Error deleting settings"); +} + 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;