Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9945aa7
Add API endpoint test cases
rtweera Feb 18, 2025
887f002
Add mock service implementation for client tests
rtweera Feb 18, 2025
44ad69c
Update and fix test cases for client testing.
rtweera Feb 19, 2025
7604f4b
Update and fix mock service for edge cases
rtweera Feb 19, 2025
fc64160
Add updated Dependencies.toml
rtweera Feb 19, 2025
88304e9
Merge pull request #4 from rtweera/test
rtweera Feb 19, 2025
2a280bf
Update the license header in mock_service.bal file
rtweera Feb 20, 2025
4ab1e05
Fix extra parentheses in test.bal
rtweera Feb 20, 2025
8313a8b
Fix spelling mistakes in test.bal
rtweera Feb 20, 2025
b46d0a5
Remove debug print statement from test.bal
rtweera Feb 20, 2025
7095ee8
Add license header to test.bal
rtweera Feb 20, 2025
7ebc30e
Bal format the entire module
rtweera Feb 20, 2025
47f6f2b
Add missing license for client, types, utils files
rtweera Feb 20, 2025
ac3f788
Add updated Dependencies.toml file
rtweera Feb 20, 2025
20a198c
Merge pull request #5 from rtweera/test
rtweera Feb 20, 2025
03bc6f3
Remove unnecessary test configurations
rtweera Feb 20, 2025
7318152
Merge pull request #6 from rtweera/test
rtweera Feb 20, 2025
4022357
Remove delay in live tests for get method
rtweera Feb 21, 2025
f55efa7
Add test case descriptions
rtweera Feb 21, 2025
8ece220
Remove unused import ballerina/lang.runtime
rtweera Feb 21, 2025
2fbb920
Remove unused import ballerina/lang.runtime
rtweera Feb 21, 2025
9b08541
Merge branch origin test into test
rtweera Feb 21, 2025
488ce6d
Merge pull request #7 from rtweera/test
rtweera Feb 21, 2025
2ebddb4
Fix improper use of assertTrue in test.bal
rtweera Feb 24, 2025
418d81d
Use final variables for incorrectAppId in test.bal
rtweera Feb 24, 2025
2dc3804
Merge pull request #8 from rtweera/test
rtweera Feb 24, 2025
972f217
Move all configurable values to Config.toml
rtweera Feb 24, 2025
856504f
Merge pull request #9 from rtweera/test
rtweera Feb 24, 2025
470dfc7
Add defaults for configurable variables in test.bal
rtweera Feb 24, 2025
9b18f46
Rename client to a simpler name
rtweera Feb 24, 2025
a9d714a
Merge pull request #10 from rtweera/test
rtweera Feb 24, 2025
6319531
Update variable to check for a live server
Nuvindu Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -194,6 +194,9 @@ version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -263,9 +266,6 @@ dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "os", moduleName = "os"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -327,7 +327,7 @@ name = "hubspot.crm.extensions.videoconferencing"
version = "1.0.0"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "url"},
{org = "ballerinai", name = "observe"}
Expand Down
19 changes: 18 additions & 1 deletion ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
55 changes: 55 additions & 0 deletions ballerina/tests/mock_service.bal
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;
}
}
151 changes: 151 additions & 0 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// 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/lang.runtime;
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 = <int:Signed32>appId;
final string serviceUrl = isLiveServer ? liveServerUrl : localServerUrl;
final Client hubSpotVideoConferencing = 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 hubSpotVideoConferencing->/[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 = hubSpotVideoConferencing->/[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 hubSpotVideoConferencing->/[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 = hubSpotVideoConferencing->/[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 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:Config {
enable: true,
dependsOn: [testPutSettings]
}
function testGetIncorrectAppId() returns error? {
ExternalSettings|http:ClientRequestError|error settings = hubSpotVideoConferencing->/[1234]();
test:assertTrue(settings is http:ClientRequestError, "Error getting settings");
}

@test:Config {
enable: true,
dependsOn: [testGetSettings]
}
function testDeleteIncorrectAppId() returns error? {
http:Response response = check hubSpotVideoConferencing->/[1234].delete();
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 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:Config {
enable: true,
dependsOn: [testGetSettings]
}
function testDeleteSettingsAgain() returns error? {
http:Response response = check hubSpotVideoConferencing->/[appIdSigned32].delete();
test:assertTrue(response.statusCode == 204, "Error deleting settings");
}

18 changes: 17 additions & 1 deletion ballerina/types.bal
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 17 additions & 1 deletion ballerina/utils.bal
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Loading