From d7897e0a56071847297276d70ccb93bc47094e13 Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Tue, 18 Feb 2025 11:44:21 +0530 Subject: [PATCH 1/7] Add live server tests in test.bal --- ballerina/Dependencies.toml | 293 ++++++++++++++++++++++++++++++++++++ ballerina/tests/test.bal | 264 ++++++++++++++++++++++++++++++++ 2 files changed, 557 insertions(+) create mode 100644 ballerina/tests/test.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9e25f2f..29001d6 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -7,11 +7,249 @@ dependencies-toml-version = "2" distribution-version = "2201.11.0" +[[package]] +org = "ballerina" +name = "auth" +version = "2.13.0" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"} +] + +[[package]] +org = "ballerina" +name = "cache" +version = "3.9.0" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "task"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "constraint" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "crypto" +version = "2.8.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "data.jsondata" +version = "1.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "file" +version = "1.11.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "http" +version = "2.13.2" +dependencies = [ + {org = "ballerina", name = "auth"}, + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "data.jsondata"}, + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.decimal"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "oauth2"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] +modules = [ + {org = "ballerina", packageName = "http", moduleName = "http"}, + {org = "ballerina", packageName = "http", moduleName = "http.httpscerr"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.7.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] + [[package]] org = "ballerina" name = "jballerina.java" version = "0.0.0" +[[package]] +org = "ballerina" +name = "jwt" +version = "2.14.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.decimal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.int" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "lang.regexp" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.runtime" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.string" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.regexp"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "log" +version = "2.11.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "observe"} +] + +[[package]] +org = "ballerina" +name = "mime" +version = "2.11.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "log"} +] + +[[package]] +org = "ballerina" +name = "oauth2" +version = "2.13.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] +modules = [ + {org = "ballerina", packageName = "oauth2", moduleName = "oauth2"} +] + [[package]] org = "ballerina" name = "observe" @@ -20,6 +258,57 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "os" +version = "1.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "task" +version = "2.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "time" +version = "2.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "url" +version = "2.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "url", moduleName = "url"} +] + [[package]] org = "ballerinai" name = "observe" @@ -37,6 +326,10 @@ org = "ballerinax" name = "hubspot.crm.engagements.tasks" version = "1.0.0" dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "oauth2"}, + {org = "ballerina", name = "test"}, + {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} ] modules = [ diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal new file mode 100644 index 0000000..2504f7d --- /dev/null +++ b/ballerina/tests/test.bal @@ -0,0 +1,264 @@ +// 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/oauth2; +import ballerina/test; + +configurable boolean isLiveServer = ?; +final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/objects/tasks" : "http://localhost:9090/crm/v3/objects/tasks"; + +configurable string clientId=?; +configurable string clientSecret = ?; +configurable string refreshToken = ?; + +isolated function initClient() returns Client|error { + if isLiveServer { + OAuth2RefreshTokenGrantConfig auth = { + clientId: clientId, + clientSecret: clientSecret, + refreshToken: refreshToken, + credentialBearer: oauth2:POST_BODY_BEARER + }; + return check new ({auth}, serviceUrl); + } + return check new ({ + auth: { + token: "test-token" + } + }, serviceUrl); +} + +final Client taskClient = check initClient(); +final string testTaskId = "76798578391"; +final string updateTestTaskId = "76798578391"; +final string deletedTaskId = "76798588649"; +final string testBatchTaskId1 = "77192492773"; +final string testBatchTaskId2 = "77200500438"; +final string updateTestsubject = "test update task"; +final string testBatchTaskArchieveId1 = "77151529671"; +final string testBatchTaskArchieveId2 = "77151529672"; +final string testBatchTaskUpdated1 = "77200500438"; +final string testBatchTaskUpdated2 = "77195047646"; + +@test:Config { + enable: isLiveServer +} +isolated function testGetTasksById() returns error? { + SimplePublicObjectWithAssociations response = check taskClient->/[testTaskId]; + test:assertEquals(response?.properties, { + "hs_createdate": "2025-02-17T09:24:49.394Z", + "hs_lastmodifieddate": "2025-02-17T11:12:50.511Z", + "hs_object_id": "76798578391" + }); +} + +@test:Config { + enable: isLiveServer +} +isolated function testUpdateTask() returns error? { + SimplePublicObject response = check taskClient->/[updateTestTaskId].patch(payload = { + "objectWriteTraceId": "string", + "properties": { + "hs_task_subject": updateTestsubject + } + }); + if(response is SimplePublicObject){ + test:assertTrue(response.length() > 0,msg="Task update failed. Please check the input data or server response for issues."); + +} +} + +@test:Config { + enable: isLiveServer +} +isolated function testTaskDeleteById() returns error? { + http:Response response = check taskClient->/[deletedTaskId].delete(); + test:assertTrue(response.statusCode == 204,msg="Task deletion failed. Please check the input data or server response for issues."); +} + +@test:Config {} +isolated function testTasksBatchRead() returns error? { + BatchReadInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskId1}, {"id": testBatchTaskId2}], propertiesWithHistory: ["hs_task_subject", "hs_timestamp"], properties: ["hs_task_subject", "hs_task_status"]}; + BatchResponseSimplePublicObject response = check taskClient->/batch/read.post(payload = batchTaskInput); + if(response is BatchResponseSimplePublicObject){ + test:assertTrue(response.results.length() > 0, msg = "Batch task read failed. Please check the input data or server response for issues."); + } +} + +@test:Config { + enable:isLiveServer +} +isolated function testTaskBatchUpsert() returns error? { +} + +@test:Config { + enable:isLiveServer +} +isolated function testTaskSearch() returns error? { + PublicObjectSearchRequest taskSearchInput={query:"test"}; + CollectionResponseWithTotalSimplePublicObjectForwardPaging response= check taskClient->/search.post(payload=taskSearchInput); + if(response is CollectionResponseWithTotalSimplePublicObjectForwardPaging){ + test:assertTrue(response?.results.length()>0, msg="Task search failed. Please check the input data or server response for issues."); + } +} + +@test:Config { + enable: isLiveServer +} +isolated function testBatchTasksUpdate() returns error? { + BatchInputSimplePublicObjectBatchInput batchTaskInput = { + "inputs": [ + { + + "objectWriteTraceId": "string1", + "id": "77200500438", + "properties": { + "hs_task_subject": "Updating with test batch update1" + } + }, + { + + "objectWriteTraceId": "string2", + "id": "77195047646", + "properties": { + "hs_task_subject": "Updating with test batch update2" + } + } + ] + }; + BatchResponseSimplePublicObject response = check taskClient->/batch/update.post(payload = batchTaskInput); + if(response is BatchResponseSimplePublicObject){ + test:assertTrue(response?.results.length()>0, msg = "Batch task update failed. Please check the input data or server response for issues."); + } +} + +@test:Config { + enable: isLiveServer +} +isolated function testTasksBatchCreate() returns error? +{ + BatchInputSimplePublicObjectInputForCreate batchTaskInput = { + "inputs": [ + { + "associations": [ + { + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 192 + } + ], + "to": { + "id": "38349931215" + } + } + ], + "objectWriteTraceId": "string2", + "properties": { + "hs_timestamp": "2025-10-30T03:30:17.883Z", + "hs_task_body": "test batch task body1", + "hs_task_subject": "test batch task subject1", + "hs_task_status": "WAITING", + "hs_task_priority": "HIGH", + "hs_task_type": "TODO" + } + }, + { + "associations": [ + { + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 192 + } + ], + "to": { + "id": "38349931215" + } + } + ], + "objectWriteTraceId": "string1", + "properties": { + "hs_timestamp": "2025-10-30T03:30:17.883Z", + "hs_task_body": "test batch task body2", + "hs_task_subject": "test batch task subject2", + "hs_task_status": "WAITING", + "hs_task_priority": "HIGH", + "hs_task_type": "TODO" + } + } + ] + }; + BatchResponseSimplePublicObject response = check taskClient->/batch/create.post(payload = batchTaskInput); + if(response is BatchResponseSimplePublicObject){ + test:assertTrue(response?.results.length()>0, msg = "Batch task creation failed. Please check the input data or server response for issues."); + } + +} + +@test:Config { + enable: isLiveServer +} +isolated function testTasksBatchArchieve() returns error? { + BatchInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskArchieveId1}, {"id": testBatchTaskArchieveId2}]}; + http:Response response = check taskClient->/batch/archive.post(payload = batchTaskInput); + test:assertTrue(response.statusCode == 204, msg = "Batch task archieve failed. Please check the input data or server response for issues."); +} + +@test:Config { + enable: isLiveServer +} +isolated function testTaskCreate() returns error? { + SimplePublicObjectInputForCreate taskCreateInput = { + "associations": [ + { + "to": { + "id": "84267202257" + }, + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 204 + } + ] + } + ], + "objectWriteTraceId": "string", + "properties": { + "hs_timestamp": "2025-02-20T03:30:17.883Z", + "hs_task_body": "Sample task body", + "hs_task_priority": "LOW", + "hs_task_type": "TODO", + "hs_task_subject": "A sample task for testing task creation" + } + }; + SimplePublicObject response = check taskClient->/.post(payload = taskCreateInput); + test:assertTrue(response is SimplePublicObject, msg = "Task creation failed."); +} + +@test:Config { + enable: isLiveServer +} +isolated function testTasksGetPage() returns error? { + CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check taskClient->/.get(); + if(response is CollectionResponseSimplePublicObjectWithAssociationsForwardPaging){ + test:assertTrue(response.results.length() > 0, msg = "Failed to retrieve tasks of a page"); + } +} From 357fc8f93b2bf8dd085ec19d3d895eae86f35eef Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Wed, 19 Feb 2025 00:28:13 +0530 Subject: [PATCH 2/7] Add mock services for test cases --- ballerina/Dependencies.toml | 8 + ballerina/tests/mock_service.bal | 518 +++++++++++++++++++++++++++++++ ballerina/tests/test.bal | 151 +++++++-- 3 files changed, 651 insertions(+), 26 deletions(-) create mode 100644 ballerina/tests/mock_service.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 29001d6..c77ce67 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" @@ -222,6 +225,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -327,6 +333,8 @@ name = "hubspot.crm.engagements.tasks" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "log"}, {org = "ballerina", name = "oauth2"}, {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal new file mode 100644 index 0000000..107a780 --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -0,0 +1,518 @@ +// AUTO-GENERATED FILE. +// This file is auto-generated by the Ballerina OpenAPI tool. + +import ballerina/http; +import ballerina/log; + +// import ballerina/lang.regexp; + +listener http:Listener httpListener = new (9090); + +http:Service mockService = service object { + # Archive a task + # + # + return - returns can be any of following types + # http:NoContent (No content) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function delete [string taskId]() returns http:Response|error { + http:Response response = new; + // boolean isNumeric=check taskId.isNumeric(); + response.statusCode = 204; + return response; + } + + # List of the tasks + # + # + 'limit - The maximum number of results to display per page. + # + after - The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. + # + properties - A comma separated list of the properties to be returned in the response. If any of the specified properties are not present on the requested object(s), they will be ignored. + # + propertiesWithHistory - A comma separated list of the properties to be returned along with their history of previous values. If any of the specified properties are not present on the requested object(s), they will be ignored. Usage of this parameter will reduce the maximum number of objects that can be read by a single request. + # + associations - A comma separated list of object types to retrieve associated IDs for. If any of the specified associations do not exist, they will be ignored. + # + archived - Whether to return only results that have been archived. + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function get .(string? after, string[]? properties, string[]? propertiesWithHistory, string[]? associations, int:Signed32 'limit = 10, boolean archived = false) returns CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error { + return + { + "results": [ + { + "id": "76578958019", + "properties": { + "hs_createdate": "2025-02-17T09:24:49.394Z", + "hs_lastmodifieddate": "2025-02-18T08:24:36.446Z", + "hs_object_id": "76578958019", + "hs_task_subject": "Hello task 1", + "hubspot_owner_id": null + }, + "createdAt": "2025-02-16T12:15:45.113Z", + "updatedAt": "2025-02-16T12:15:45.724Z", + "archived": false + }, + { + "id": "76798578391", + "properties": { + "hs_createdate": "2025-02-17T09:24:49.394Z", + "hs_lastmodifieddate": "2025-02-17T11:12:50.511Z", + "hs_object_id": "76798578391", + "hs_task_subject": "Hello task2", + "hubspot_owner_id": "77367890" + }, + "createdAt": "2025-02-17T09:24:49.394Z", + "updatedAt": "2025-02-17T11:12:50.511Z", + "archived": false + } + ] + + }; + } + + # Read a task + # + # + properties - A comma separated list of the properties to be returned in the response. If any of the specified properties are not present on the requested object(s), they will be ignored. + # + propertiesWithHistory - A comma separated list of the properties to be returned along with their history of previous values. If any of the specified properties are not present on the requested object(s), they will be ignored. + # + associations - A comma separated list of object types to retrieve associated IDs for. If any of the specified associations do not exist, they will be ignored. + # + archived - Whether to return only results that have been archived. + # + idProperty - The name of a property whose values are unique for this object type + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function get [string taskId](string[]? properties, string[]? propertiesWithHistory, string[]? associations, string? idProperty, boolean archived = false) returns SimplePublicObjectWithAssociations|error|http:Response { + if (taskId == "-1") + { + http:Response response = new; + response.statusCode = 404; + return response; + } + else { + + SimplePublicObjectWithAssociations response = { + "id": taskId, + "properties": { + "hs_createdate": "2025-02-17T09:24:49.394Z", + "hs_lastmodifieddate": "2025-02-18T08:24:36.446Z", + "hs_object_id": "76798578391", + "hs_task_priority": "LOW", + "hs_task_subject": "Test task for mock service", + "hs_task_type": "TODO", + "hubspot_owner_id": "77367890" + }, + "createdAt": "2025-02-18T07:55:49.513Z", + "updatedAt": "2025-02-18T07:55:50.043Z", + "archived": false + }; + return response; + } + } + + # Update a task + # + # + idProperty - The name of a property whose values are unique for this object type + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function patch [string taskId](string? idProperty, @http:Payload SimplePublicObjectInput payload) returns SimplePublicObject|http:Response|error { + if (taskId == "-1") { + http:Response response = new; + response.statusCode = 404; + return response; + } + else { + SimplePublicObject response = { + "id": taskId, + "properties": { + "hs_all_owner_ids": "77367890", + "hs_created_by": "77367890", + "hs_created_by_user_id": "77367890", + "hs_createdate": "2025-02-18T07:55:49.513Z", + "hs_lastmodifieddate": "2025-02-18T07:55:50.043Z", + "hs_modified_by": "77367890", + "hs_object_id": "77483577066", + "hs_object_source": "CRM_UI", + "hs_object_source_id": "userId:77367890", + "hs_object_source_label": "CRM_UI", + "hs_object_source_user_id": "77367890", + "hs_pipeline": "3d314325-1b2a-4225-9388-375f49c57ec3", + "hs_pipeline_stage": "af0e6a5c-2ea3-4c72-b69f-7c6cb3fdb591", + "hs_task_subject": "Test task for mock service", + "hs_updated_by_user_id": "77367890", + "hs_user_ids_of_all_owners": "77367890", + "hubspot_owner_assigneddate": "2025-02-18T07:55:49.513Z", + "hubspot_owner_id": "77367890" + }, + "createdAt": "2025-02-18T07:55:49.513Z", + "updatedAt": "2025-02-18T07:55:50.043Z", + "archived": false + }; + return response; + } + + } + + # Create a task + # + # + return - returns can be any of following types + # http:Created (successful operation) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post .(@http:Payload SimplePublicObjectInputForCreate payload) returns SimplePublicObject|http:Response|error { + string associationToId = payload.associations[0].to.id; // get the association id + if (associationToId == "-1") + { + http:Response response = new; + response.statusCode = 404; + return response; + } + else { + + SimplePublicObject response = { + "id": "77597502155", + "properties": { + "hs_body_preview": "Sample task body", + "hs_body_preview_html": "\n \n \n Sample task body\n \n", + "hs_body_preview_is_truncated": "false", + "hs_createdate": "2025-02-18T08:46:39.901Z", + "hs_lastmodifieddate": "2025-02-18T08:46:39.901Z", + "hs_object_id": "77597502155", + "hs_object_source": "INTEGRATION", + "hs_object_source_id": "8111832", + "hs_object_source_label": "INTEGRATION", + "hs_task_body": "Sample task body", + "hs_task_completion_count": "0", + "hs_task_family": "SALES", + "hs_task_for_object_type": "OWNER", + "hs_task_is_all_day": "false", + "hs_task_is_completed": "0", + "hs_task_is_completed_call": "0", + "hs_task_is_completed_email": "0", + "hs_task_is_completed_linked_in": "0", + "hs_task_is_completed_sequence": "0", + "hs_task_is_overdue": "false", + "hs_task_is_past_due_date": "false", + "hs_task_missed_due_date": "false", + "hs_task_missed_due_date_count": "0", + "hs_task_priority": "LOW", + "hs_task_status": "NOT_STARTED", + "hs_task_subject": "A sample task for testing task creation", + "hs_task_type": "TODO", + "hs_timestamp": "2025-02-20T03:30:17.883Z" + }, + "createdAt": "2025-02-18T08:46:39.901Z", + "updatedAt": "2025-02-18T08:46:39.901Z", + "archived": false + }; + + return response; + } + } + + # Archive a batch of tasks by ID + # + # + return - returns can be any of following types + # http:NoContent (No content) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post batch/archive(@http:Payload BatchInputSimplePublicObjectId payload) returns http:Response|error { + http:Response response = new; + response.statusCode = 204; + return response; + } + + # Create a batch of tasks + # + # + return - returns can be any of following types + # http:Created (successful operation) + # http:MultiStatus (multiple statuses) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post batch/create(@http:Payload BatchInputSimplePublicObjectInputForCreate payload) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|http:Response|error { + string associationToId1 = payload.inputs[0].associations[0].to.id; // get the associationTo id1 + string associationToId2 = payload.inputs[1].associations[0].to.id; // get the associationTo id2 + if (associationToId1 == "-1" || associationToId2 == "-1") + { + http:Response response = new; + response.statusCode = 404; + return response; + } + else { + BatchResponseSimplePublicObject response = { + "status": "COMPLETE", + "results": [ + { + "id": "77255875305", + "properties": { + "hs_body_preview": "test batch task body2", + "hs_body_preview_html": "\n \n \n test batch task body2\n \n", + "hs_body_preview_is_truncated": "false", + "hs_createdate": "2025-02-18T09:09:19.978Z", + "hs_lastmodifieddate": "2025-02-18T09:09:19.978Z", + "hs_object_id": "77255875305", + "hs_object_source": "INTEGRATION", + "hs_object_source_id": "8111832", + "hs_object_source_label": "INTEGRATION", + "hs_task_body": "test batch task body2", + "hs_task_completion_count": "0", + "hs_task_family": "SALES", + "hs_task_for_object_type": "OWNER", + "hs_task_is_all_day": "false", + "hs_task_is_completed": "0", + "hs_task_is_completed_call": "0", + "hs_task_is_completed_email": "0", + "hs_task_is_completed_linked_in": "0", + "hs_task_is_completed_sequence": "0", + "hs_task_is_overdue": "false", + "hs_task_is_past_due_date": "false", + "hs_task_missed_due_date": "false", + "hs_task_missed_due_date_count": "0", + "hs_task_priority": "HIGH", + "hs_task_status": "WAITING", + "hs_task_subject": "test batch task subject2", + "hs_task_type": "TODO", + "hs_timestamp": "2025-10-30T03:30:17.883Z" + }, + "createdAt": "2025-02-18T09:09:19.978Z", + "updatedAt": "2025-02-18T09:09:19.978Z", + "archived": false, + "objectWriteTraceId": "string1" + }, + { + "id": "77255875304", + "properties": { + "hs_body_preview": "test batch task body1", + "hs_body_preview_html": "\n \n \n test batch task body1\n \n", + "hs_body_preview_is_truncated": "false", + "hs_createdate": "2025-02-18T09:09:19.978Z", + "hs_lastmodifieddate": "2025-02-18T09:09:19.978Z", + "hs_object_id": "77255875304", + "hs_object_source": "INTEGRATION", + "hs_object_source_id": "8111832", + "hs_object_source_label": "INTEGRATION", + "hs_task_body": "test batch task body1", + "hs_task_completion_count": "0", + "hs_task_family": "SALES", + "hs_task_for_object_type": "OWNER", + "hs_task_is_all_day": "false", + "hs_task_is_completed": "0", + "hs_task_is_completed_call": "0", + "hs_task_is_completed_email": "0", + "hs_task_is_completed_linked_in": "0", + "hs_task_is_completed_sequence": "0", + "hs_task_is_overdue": "false", + "hs_task_is_past_due_date": "false", + "hs_task_missed_due_date": "false", + "hs_task_missed_due_date_count": "0", + "hs_task_priority": "HIGH", + "hs_task_status": "WAITING", + "hs_task_subject": "test batch task subject1", + "hs_task_type": "TODO", + "hs_timestamp": "2025-10-30T03:30:17.883Z" + }, + "createdAt": "2025-02-18T09:09:19.978Z", + "updatedAt": "2025-02-18T09:09:19.978Z", + "archived": false, + "objectWriteTraceId": "string2" + } + ], + "startedAt": "2025-02-18T09:09:19.945Z", + "completedAt": "2025-02-18T09:09:20.262Z" + }; + return response; + } + } + + # Read a batch of tasks by internal ID, or unique property values + # + # + archived - Whether to return only results that have been archived. + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:MultiStatus (multiple statuses) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post batch/read(@http:Payload BatchReadInputSimplePublicObjectId payload, boolean archived = false) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error { + BatchResponseSimplePublicObject response = { + "status": "COMPLETE", + "results": [ + { + "id": "77255886563", + "properties": { + "hs_createdate": "2025-02-18T09:36:22.519Z", + "hs_lastmodifieddate": "2025-02-18T09:36:23.070Z", + "hs_object_id": "77255886563", + "hs_task_status": "NOT_STARTED", + "hs_task_subject": "Batch task1" + }, + "propertiesWithHistory": { + "hs_task_body": [ + { + "value": "Sample task body", + "timestamp": "2025-02-18T09:36:22.519Z", + "sourceType": "INTEGRATION", + "sourceId": "8111832" + } + ], + "hs_timestamp": [ + { + "value": "2025-02-20T03:30:17.883Z", + "timestamp": "2025-02-18T09:36:22.519Z", + "sourceType": "INTEGRATION", + "sourceId": "8111832" + } + ] + }, + "createdAt": "2025-02-18T09:36:22.519Z", + "updatedAt": "2025-02-18T09:36:23.070Z", + "archived": false + }, + { + "id": "77606927069", + "properties": { + "hs_createdate": "2025-02-18T09:36:57.705Z", + "hs_lastmodifieddate": "2025-02-18T09:36:58.197Z", + "hs_object_id": "77606927069", + "hs_task_status": "NOT_STARTED", + "hs_task_subject": "Batch task2" + }, + "propertiesWithHistory": { + "hs_task_body": [ + { + "value": "Sample task body", + "timestamp": "2025-02-18T09:36:57.705Z", + "sourceType": "INTEGRATION", + "sourceId": "8111832" + } + ], + "hs_timestamp": [ + { + "value": "2025-02-20T03:30:17.883Z", + "timestamp": "2025-02-18T09:36:57.705Z", + "sourceType": "INTEGRATION", + "sourceId": "8111832" + } + ] + }, + "createdAt": "2025-02-18T09:36:57.705Z", + "updatedAt": "2025-02-18T09:36:58.197Z", + "archived": false + } + ], + "startedAt": "2025-02-18T09:38:53.032Z", + "completedAt": "2025-02-18T09:38:53.039Z" + }; + return response; + } + + # Update a batch of tasks by internal ID, or unique property values + # + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:MultiStatus (multiple statuses) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post batch/update(@http:Payload BatchInputSimplePublicObjectBatchInput payload) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error { + BatchResponseSimplePublicObject response = { + "status": "COMPLETE", + "results": [ + { + "id": "77195047646", + "properties": { + "hs_createdate": "2025-02-17T17:13:54.986Z", + "hs_lastmodifieddate": "2025-02-17T17:30:25.243Z", + "hs_object_id": "77195047646", + "hs_object_source": "INTEGRATION", + "hs_object_source_id": "8111832", + "hs_object_source_label": "INTEGRATION", + "hs_pipeline": "3d314325-1b2a-4225-9388-375f49c57ec3", + "hs_pipeline_stage": "dd5826e4-c976-4654-a527-b59ada542e52", + "hs_task_subject": "Updating with test batch update2" + }, + "createdAt": "2025-02-17T17:13:54.986Z", + "updatedAt": "2025-02-17T17:30:25.243Z", + "archived": false, + "objectWriteTraceId": "string2" + }, + { + "id": "77200500438", + "properties": { + "hs_createdate": "2025-02-17T16:38:28.765Z", + "hs_lastmodifieddate": "2025-02-17T17:30:25.244Z", + "hs_object_id": "77200500438", + "hs_object_source": "INTEGRATION", + "hs_object_source_id": "8111832", + "hs_object_source_label": "INTEGRATION", + "hs_pipeline": "3d314325-1b2a-4225-9388-375f49c57ec3", + "hs_pipeline_stage": "dd5826e4-c976-4654-a527-b59ada542e52", + "hs_task_subject": "Updating with test batch update1" + }, + "createdAt": "2025-02-17T16:38:28.765Z", + "updatedAt": "2025-02-17T17:30:25.244Z", + "archived": false, + "objectWriteTraceId": "string1" + } + ], + "startedAt": "2025-02-18T09:47:19.539Z", + "completedAt": "2025-02-18T09:47:19.621Z" + }; + return response; + } + + # Create or update a batch of tasks by unique property values + # + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:MultiStatus (multiple statuses) + # http:DefaultStatusCodeResponse (An error occurred.) + // resource function post batch/upsert(@http:Payload BatchInputSimplePublicObjectBatchInputUpsert payload) returns BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors|error { + // } + + # Search for tasks + # + # + return - returns can be any of following types + # http:Ok (successful operation) + # http:DefaultStatusCodeResponse (An error occurred.) + resource function post search(@http:Payload PublicObjectSearchRequest payload) returns CollectionResponseWithTotalSimplePublicObjectForwardPaging|error { + CollectionResponseWithTotalSimplePublicObjectForwardPaging response = { + "total": 2, + "results": [ + { + "id": "76578958019", + "properties": { + "hs_createdate": "2025-02-16T12:15:45.113Z", + "hs_lastmodifieddate": "2025-02-16T12:15:45.724Z", + "hs_object_id": "76578958019", + "hs_task_body": "a task without associations", + "hs_task_status": "NOT_STARTED" + }, + "createdAt": "2025-02-16T12:15:45.113Z", + "updatedAt": "2025-02-16T12:15:45.724Z", + "archived": false + }, + { + "id": "76798585554", + "properties": { + "hs_createdate": "2025-02-17T10:52:27.816Z", + "hs_lastmodifieddate": "2025-02-17T10:52:28.299Z", + "hs_object_id": "76798585554", + "hs_task_body": "

", + "hs_task_status": "NOT_STARTED" + }, + "createdAt": "2025-02-17T10:52:27.816Z", + "updatedAt": "2025-02-17T10:52:28.299Z", + "archived": false + } + ] + }; + return response; + + } +}; + +function init() returns error? { + if isLiveServer { + log:printInfo("Skipping mock service initialization. Tests are configured to run against live server."); + return; + } + log:printInfo("Tests are configured to run against mock server. Initializing mock service..."); + check httpListener.attach(mockService, "/"); + check httpListener.'start(); +} + +// function isNumeric(string input) returns boolean { +// string regex = "^[0-9]+$"; +// // return (input, regex); + +// } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 2504f7d..9ab29d3 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -22,7 +22,7 @@ import ballerina/oauth2; import ballerina/test; configurable boolean isLiveServer = ?; -final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/objects/tasks" : "http://localhost:9090/crm/v3/objects/tasks"; +final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/objects/tasks" : "http://localhost:9090"; configurable string clientId=?; configurable string clientSecret = ?; @@ -49,8 +49,8 @@ final Client taskClient = check initClient(); final string testTaskId = "76798578391"; final string updateTestTaskId = "76798578391"; final string deletedTaskId = "76798588649"; -final string testBatchTaskId1 = "77192492773"; -final string testBatchTaskId2 = "77200500438"; +final string testBatchTaskId1 = "77255886563"; +final string testBatchTaskId2 = "77606927069"; final string updateTestsubject = "test update task"; final string testBatchTaskArchieveId1 = "77151529671"; final string testBatchTaskArchieveId2 = "77151529672"; @@ -58,19 +58,15 @@ final string testBatchTaskUpdated1 = "77200500438"; final string testBatchTaskUpdated2 = "77195047646"; @test:Config { - enable: isLiveServer } isolated function testGetTasksById() returns error? { SimplePublicObjectWithAssociations response = check taskClient->/[testTaskId]; - test:assertEquals(response?.properties, { - "hs_createdate": "2025-02-17T09:24:49.394Z", - "hs_lastmodifieddate": "2025-02-17T11:12:50.511Z", - "hs_object_id": "76798578391" - }); + if(response is SimplePublicObjectWithAssociations){ + test:assertTrue(response.length() > 0, msg = "Task retrieval failed. Please check the input data or server response for issues."); + } } -@test:Config { - enable: isLiveServer +@test:Config { } isolated function testUpdateTask() returns error? { SimplePublicObject response = check taskClient->/[updateTestTaskId].patch(payload = { @@ -86,14 +82,14 @@ isolated function testUpdateTask() returns error? { } @test:Config { - enable: isLiveServer } isolated function testTaskDeleteById() returns error? { http:Response response = check taskClient->/[deletedTaskId].delete(); test:assertTrue(response.statusCode == 204,msg="Task deletion failed. Please check the input data or server response for issues."); } -@test:Config {} +@test:Config { +} isolated function testTasksBatchRead() returns error? { BatchReadInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskId1}, {"id": testBatchTaskId2}], propertiesWithHistory: ["hs_task_subject", "hs_timestamp"], properties: ["hs_task_subject", "hs_task_status"]}; BatchResponseSimplePublicObject response = check taskClient->/batch/read.post(payload = batchTaskInput); @@ -102,14 +98,12 @@ isolated function testTasksBatchRead() returns error? { } } -@test:Config { - enable:isLiveServer +@test:Config { } isolated function testTaskBatchUpsert() returns error? { } -@test:Config { - enable:isLiveServer +@test:Config { } isolated function testTaskSearch() returns error? { PublicObjectSearchRequest taskSearchInput={query:"test"}; @@ -119,8 +113,7 @@ isolated function testTaskSearch() returns error? { } } -@test:Config { - enable: isLiveServer +@test:Config { } isolated function testBatchTasksUpdate() returns error? { BatchInputSimplePublicObjectBatchInput batchTaskInput = { @@ -149,8 +142,7 @@ isolated function testBatchTasksUpdate() returns error? { } } -@test:Config { - enable: isLiveServer +@test:Config { } isolated function testTasksBatchCreate() returns error? { @@ -213,8 +205,7 @@ isolated function testTasksBatchCreate() returns error? } -@test:Config { - enable: isLiveServer +@test:Config { } isolated function testTasksBatchArchieve() returns error? { BatchInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskArchieveId1}, {"id": testBatchTaskArchieveId2}]}; @@ -223,7 +214,6 @@ isolated function testTasksBatchArchieve() returns error? { } @test:Config { - enable: isLiveServer } isolated function testTaskCreate() returns error? { SimplePublicObjectInputForCreate taskCreateInput = { @@ -253,8 +243,7 @@ isolated function testTaskCreate() returns error? { test:assertTrue(response is SimplePublicObject, msg = "Task creation failed."); } -@test:Config { - enable: isLiveServer +@test:Config { } isolated function testTasksGetPage() returns error? { CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check taskClient->/.get(); @@ -262,3 +251,113 @@ isolated function testTasksGetPage() returns error? { test:assertTrue(response.results.length() > 0, msg = "Failed to retrieve tasks of a page"); } } +@test:Config{ +} +isolated function testGetTasksByInvalidId() returns error?{ + SimplePublicObject|error response = taskClient->/["-1"]; + test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); +} +@test:Config{ +} +isolated function testTaskCreateWithInvalidAssociationToId() returns error? +{ + SimplePublicObjectInputForCreate taskCreateInput = { + "associations": [ + { + "to": { + "id": "-1" + }, + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 204 + } + ] + } + ], + "objectWriteTraceId": "string", + "properties": { + "hs_timestamp": "2025-02-20T03:30:17.883Z", + "hs_task_body": "Sample task body", + "hs_task_priority": "LOW", + "hs_task_type": "TODO", + "hs_task_subject": "A sample task for testing task creation" + } + }; + SimplePublicObject|error response = taskClient->/.post(payload = taskCreateInput); + test:assertTrue(response is error,msg="Expected an error response for invalid associationId"); +} + +@test:Config{ +} +isolated function testTaskUpdateWithInvalidId() returns error? +{ + SimplePublicObject|error response = taskClient->/["-1"].patch(payload = { + "objectWriteTraceId": "string", + "properties": { + "hs_task_subject": updateTestsubject + } + }); + test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); +} +@test:Config{ +} +isolated function testTaskBatchCreateWithInvalidAssociationToId() returns error? +{ + BatchInputSimplePublicObjectInputForCreate batchTaskInput = { + "inputs": [ + { + "associations": [ + { + "to": { + "id": "-1" + }, + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 204 + } + ] + } + ], + "objectWriteTraceId": "string2", + "properties": { + "hs_timestamp": "2025-10-30T03:30:17.883Z", + "hs_task_body": "test batch task body1", + "hs_task_subject": "test batch task subject1", + "hs_task_status": "WAITING", + "hs_task_priority": "HIGH", + "hs_task_type": "TODO" + } + }, + { + "associations": [ + { + "to": { + "id": "-2" + }, + "types": [ + { + "associationCategory": "HUBSPOT_DEFINED", + "associationTypeId": 204 + } + ] + } + ], + "objectWriteTraceId": "string1", + "properties": { + "hs_timestamp": "2025-10-30T03:30:17.883Z", + "hs_task_body": "test batch task body2", + "hs_task_subject": "test batch task subject2", + "hs_task_status": "WAITING", + "hs_task_priority": "HIGH", + "hs_task_type": "TODO" + } + } + ] + }; + BatchResponseSimplePublicObject|error response = taskClient->/batch/create.post(payload = batchTaskInput); + test:assertTrue(response is error,msg="Expected an error response for invalid associationId"); +} + + From 6bb9fffcf8f06b42c24cc651d5924f6c34390dc6 Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Wed, 19 Feb 2025 09:49:14 +0530 Subject: [PATCH 3/7] Add test groups --- ballerina/Dependencies.toml | 4 ---- ballerina/tests/mock_service.bal | 12 ------------ ballerina/tests/test.bal | 29 ++++++++++++++++++++--------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c77ce67..9ee77f1 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -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" @@ -333,7 +330,6 @@ name = "hubspot.crm.engagements.tasks" version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, - {org = "ballerina", name = "io"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "oauth2"}, {org = "ballerina", name = "test"}, diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 107a780..d066ce4 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -4,8 +4,6 @@ import ballerina/http; import ballerina/log; -// import ballerina/lang.regexp; - listener http:Listener httpListener = new (9090); http:Service mockService = service object { @@ -16,7 +14,6 @@ http:Service mockService = service object { # http:DefaultStatusCodeResponse (An error occurred.) resource function delete [string taskId]() returns http:Response|error { http:Response response = new; - // boolean isNumeric=check taskId.isNumeric(); response.statusCode = 204; return response; } @@ -63,7 +60,6 @@ http:Service mockService = service object { "archived": false } ] - }; } @@ -85,7 +81,6 @@ http:Service mockService = service object { return response; } else { - SimplePublicObjectWithAssociations response = { "id": taskId, "properties": { @@ -163,7 +158,6 @@ http:Service mockService = service object { return response; } else { - SimplePublicObject response = { "id": "77597502155", "properties": { @@ -510,9 +504,3 @@ function init() returns error? { check httpListener.attach(mockService, "/"); check httpListener.'start(); } - -// function isNumeric(string input) returns boolean { -// string regex = "^[0-9]+$"; -// // return (input, regex); - -// } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 9ab29d3..adb9fec 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -23,7 +23,6 @@ import ballerina/test; configurable boolean isLiveServer = ?; final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/objects/tasks" : "http://localhost:9090"; - configurable string clientId=?; configurable string clientSecret = ?; configurable string refreshToken = ?; @@ -58,6 +57,7 @@ final string testBatchTaskUpdated1 = "77200500438"; final string testBatchTaskUpdated2 = "77195047646"; @test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testGetTasksById() returns error? { SimplePublicObjectWithAssociations response = check taskClient->/[testTaskId]; @@ -66,7 +66,8 @@ isolated function testGetTasksById() returns error? { } } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testUpdateTask() returns error? { SimplePublicObject response = check taskClient->/[updateTestTaskId].patch(payload = { @@ -82,13 +83,15 @@ isolated function testUpdateTask() returns error? { } @test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTaskDeleteById() returns error? { http:Response response = check taskClient->/[deletedTaskId].delete(); test:assertTrue(response.statusCode == 204,msg="Task deletion failed. Please check the input data or server response for issues."); } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTasksBatchRead() returns error? { BatchReadInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskId1}, {"id": testBatchTaskId2}], propertiesWithHistory: ["hs_task_subject", "hs_timestamp"], properties: ["hs_task_subject", "hs_task_status"]}; @@ -103,7 +106,8 @@ isolated function testTasksBatchRead() returns error? { isolated function testTaskBatchUpsert() returns error? { } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTaskSearch() returns error? { PublicObjectSearchRequest taskSearchInput={query:"test"}; @@ -114,12 +118,12 @@ isolated function testTaskSearch() returns error? { } @test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testBatchTasksUpdate() returns error? { BatchInputSimplePublicObjectBatchInput batchTaskInput = { "inputs": [ { - "objectWriteTraceId": "string1", "id": "77200500438", "properties": { @@ -127,7 +131,6 @@ isolated function testBatchTasksUpdate() returns error? { } }, { - "objectWriteTraceId": "string2", "id": "77195047646", "properties": { @@ -142,7 +145,8 @@ isolated function testBatchTasksUpdate() returns error? { } } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTasksBatchCreate() returns error? { @@ -205,7 +209,8 @@ isolated function testTasksBatchCreate() returns error? } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTasksBatchArchieve() returns error? { BatchInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskArchieveId1}, {"id": testBatchTaskArchieveId2}]}; @@ -214,6 +219,7 @@ isolated function testTasksBatchArchieve() returns error? { } @test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTaskCreate() returns error? { SimplePublicObjectInputForCreate taskCreateInput = { @@ -243,7 +249,8 @@ isolated function testTaskCreate() returns error? { test:assertTrue(response is SimplePublicObject, msg = "Task creation failed."); } -@test:Config { +@test:Config { + groups: ["live_tests", "mock_tests"] } isolated function testTasksGetPage() returns error? { CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check taskClient->/.get(); @@ -252,12 +259,14 @@ isolated function testTasksGetPage() returns error? { } } @test:Config{ + groups: ["live_tests", "mock_tests"] } isolated function testGetTasksByInvalidId() returns error?{ SimplePublicObject|error response = taskClient->/["-1"]; test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); } @test:Config{ + groups: ["live_tests", "mock_tests"] } isolated function testTaskCreateWithInvalidAssociationToId() returns error? { @@ -289,6 +298,7 @@ isolated function testTaskCreateWithInvalidAssociationToId() returns error? } @test:Config{ + groups: ["live_tests", "mock_tests"] } isolated function testTaskUpdateWithInvalidId() returns error? { @@ -301,6 +311,7 @@ isolated function testTaskUpdateWithInvalidId() returns error? test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); } @test:Config{ + groups: ["live_tests", "mock_tests"] } isolated function testTaskBatchCreateWithInvalidAssociationToId() returns error? { From 2c797b7bd86996a37e316a750d0da6f7e2cde2be Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Wed, 19 Feb 2025 21:41:02 +0530 Subject: [PATCH 4/7] Add licence header to mock_service.bal and remove unnecessary parantheses --- ballerina/tests/mock_service.bal | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index d066ce4..eff60bc 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -1,5 +1,18 @@ -// AUTO-GENERATED FILE. -// 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/log; @@ -74,7 +87,7 @@ http:Service mockService = service object { # http:Ok (successful operation) # http:DefaultStatusCodeResponse (An error occurred.) resource function get [string taskId](string[]? properties, string[]? propertiesWithHistory, string[]? associations, string? idProperty, boolean archived = false) returns SimplePublicObjectWithAssociations|error|http:Response { - if (taskId == "-1") + if taskId == "-1" { http:Response response = new; response.statusCode = 404; @@ -107,7 +120,7 @@ http:Service mockService = service object { # http:Ok (successful operation) # http:DefaultStatusCodeResponse (An error occurred.) resource function patch [string taskId](string? idProperty, @http:Payload SimplePublicObjectInput payload) returns SimplePublicObject|http:Response|error { - if (taskId == "-1") { + if taskId == "-1" { http:Response response = new; response.statusCode = 404; return response; @@ -151,7 +164,7 @@ http:Service mockService = service object { # http:DefaultStatusCodeResponse (An error occurred.) resource function post .(@http:Payload SimplePublicObjectInputForCreate payload) returns SimplePublicObject|http:Response|error { string associationToId = payload.associations[0].to.id; // get the association id - if (associationToId == "-1") + if associationToId == "-1" { http:Response response = new; response.statusCode = 404; @@ -219,7 +232,7 @@ http:Service mockService = service object { resource function post batch/create(@http:Payload BatchInputSimplePublicObjectInputForCreate payload) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|http:Response|error { string associationToId1 = payload.inputs[0].associations[0].to.id; // get the associationTo id1 string associationToId2 = payload.inputs[1].associations[0].to.id; // get the associationTo id2 - if (associationToId1 == "-1" || associationToId2 == "-1") + if associationToId1 == "-1" || associationToId2 == "-1" { http:Response response = new; response.statusCode = 404; From cbe760a53f4acc0f77324a1805d99da2e9b6b5c5 Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Wed, 19 Feb 2025 22:01:44 +0530 Subject: [PATCH 5/7] Remove unnecessary lines and parantheses in test.bal file --- ballerina/tests/test.bal | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index adb9fec..18900a6 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.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, @@ -61,7 +58,7 @@ final string testBatchTaskUpdated2 = "77195047646"; } isolated function testGetTasksById() returns error? { SimplePublicObjectWithAssociations response = check taskClient->/[testTaskId]; - if(response is SimplePublicObjectWithAssociations){ + if response is SimplePublicObjectWithAssociations { test:assertTrue(response.length() > 0, msg = "Task retrieval failed. Please check the input data or server response for issues."); } } @@ -76,7 +73,7 @@ isolated function testUpdateTask() returns error? { "hs_task_subject": updateTestsubject } }); - if(response is SimplePublicObject){ + if response is SimplePublicObject { test:assertTrue(response.length() > 0,msg="Task update failed. Please check the input data or server response for issues."); } @@ -96,7 +93,7 @@ isolated function testTaskDeleteById() returns error? { isolated function testTasksBatchRead() returns error? { BatchReadInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskId1}, {"id": testBatchTaskId2}], propertiesWithHistory: ["hs_task_subject", "hs_timestamp"], properties: ["hs_task_subject", "hs_task_status"]}; BatchResponseSimplePublicObject response = check taskClient->/batch/read.post(payload = batchTaskInput); - if(response is BatchResponseSimplePublicObject){ + if response is BatchResponseSimplePublicObject { test:assertTrue(response.results.length() > 0, msg = "Batch task read failed. Please check the input data or server response for issues."); } } @@ -112,7 +109,7 @@ isolated function testTaskBatchUpsert() returns error? { isolated function testTaskSearch() returns error? { PublicObjectSearchRequest taskSearchInput={query:"test"}; CollectionResponseWithTotalSimplePublicObjectForwardPaging response= check taskClient->/search.post(payload=taskSearchInput); - if(response is CollectionResponseWithTotalSimplePublicObjectForwardPaging){ + if response is CollectionResponseWithTotalSimplePublicObjectForwardPaging { test:assertTrue(response?.results.length()>0, msg="Task search failed. Please check the input data or server response for issues."); } } @@ -140,7 +137,7 @@ isolated function testBatchTasksUpdate() returns error? { ] }; BatchResponseSimplePublicObject response = check taskClient->/batch/update.post(payload = batchTaskInput); - if(response is BatchResponseSimplePublicObject){ + if response is BatchResponseSimplePublicObject { test:assertTrue(response?.results.length()>0, msg = "Batch task update failed. Please check the input data or server response for issues."); } } @@ -203,7 +200,7 @@ isolated function testTasksBatchCreate() returns error? ] }; BatchResponseSimplePublicObject response = check taskClient->/batch/create.post(payload = batchTaskInput); - if(response is BatchResponseSimplePublicObject){ + if response is BatchResponseSimplePublicObject { test:assertTrue(response?.results.length()>0, msg = "Batch task creation failed. Please check the input data or server response for issues."); } @@ -254,7 +251,7 @@ isolated function testTaskCreate() returns error? { } isolated function testTasksGetPage() returns error? { CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check taskClient->/.get(); - if(response is CollectionResponseSimplePublicObjectWithAssociationsForwardPaging){ + if response is CollectionResponseSimplePublicObjectWithAssociationsForwardPaging { test:assertTrue(response.results.length() > 0, msg = "Failed to retrieve tasks of a page"); } } From 67093fca262aa191c5df4cd4d0a771288afd4cb0 Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Thu, 20 Feb 2025 12:17:52 +0530 Subject: [PATCH 6/7] Replace JSON payloads with Ballerina records in test.bal and mock_service.bal files --- ballerina/Dependencies.toml | 2 +- ballerina/tests/mock_service.bal | 169 +++++++++++++++---------------- ballerina/tests/test.bal | 118 ++++++++++----------- 3 files changed, 143 insertions(+), 146 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9ee77f1..c9c835a 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"}, diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index eff60bc..23fbeb0 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -45,32 +45,32 @@ http:Service mockService = service object { resource function get .(string? after, string[]? properties, string[]? propertiesWithHistory, string[]? associations, int:Signed32 'limit = 10, boolean archived = false) returns CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error { return { - "results": [ + results: [ { - "id": "76578958019", - "properties": { + id: "76578958019", + properties: { "hs_createdate": "2025-02-17T09:24:49.394Z", "hs_lastmodifieddate": "2025-02-18T08:24:36.446Z", "hs_object_id": "76578958019", "hs_task_subject": "Hello task 1", "hubspot_owner_id": null }, - "createdAt": "2025-02-16T12:15:45.113Z", - "updatedAt": "2025-02-16T12:15:45.724Z", - "archived": false + createdAt: "2025-02-16T12:15:45.113Z", + updatedAt: "2025-02-16T12:15:45.724Z", + archived: false }, { - "id": "76798578391", - "properties": { + id: "76798578391", + properties: { "hs_createdate": "2025-02-17T09:24:49.394Z", "hs_lastmodifieddate": "2025-02-17T11:12:50.511Z", "hs_object_id": "76798578391", "hs_task_subject": "Hello task2", "hubspot_owner_id": "77367890" }, - "createdAt": "2025-02-17T09:24:49.394Z", - "updatedAt": "2025-02-17T11:12:50.511Z", - "archived": false + createdAt: "2025-02-17T09:24:49.394Z", + updatedAt: "2025-02-17T11:12:50.511Z", + archived: false } ] }; @@ -95,8 +95,8 @@ http:Service mockService = service object { } else { SimplePublicObjectWithAssociations response = { - "id": taskId, - "properties": { + id: taskId, + properties: { "hs_createdate": "2025-02-17T09:24:49.394Z", "hs_lastmodifieddate": "2025-02-18T08:24:36.446Z", "hs_object_id": "76798578391", @@ -105,9 +105,9 @@ http:Service mockService = service object { "hs_task_type": "TODO", "hubspot_owner_id": "77367890" }, - "createdAt": "2025-02-18T07:55:49.513Z", - "updatedAt": "2025-02-18T07:55:50.043Z", - "archived": false + createdAt: "2025-02-18T07:55:49.513Z", + updatedAt: "2025-02-18T07:55:50.043Z", + archived: false }; return response; } @@ -127,8 +127,8 @@ http:Service mockService = service object { } else { SimplePublicObject response = { - "id": taskId, - "properties": { + id: taskId, + properties: { "hs_all_owner_ids": "77367890", "hs_created_by": "77367890", "hs_created_by_user_id": "77367890", @@ -148,9 +148,9 @@ http:Service mockService = service object { "hubspot_owner_assigneddate": "2025-02-18T07:55:49.513Z", "hubspot_owner_id": "77367890" }, - "createdAt": "2025-02-18T07:55:49.513Z", - "updatedAt": "2025-02-18T07:55:50.043Z", - "archived": false + createdAt: "2025-02-18T07:55:49.513Z", + updatedAt: "2025-02-18T07:55:50.043Z", + archived: false }; return response; } @@ -172,8 +172,8 @@ http:Service mockService = service object { } else { SimplePublicObject response = { - "id": "77597502155", - "properties": { + id: "77597502155", + properties: { "hs_body_preview": "Sample task body", "hs_body_preview_html": "\n \n \n Sample task body\n \n", "hs_body_preview_is_truncated": "false", @@ -203,9 +203,9 @@ http:Service mockService = service object { "hs_task_type": "TODO", "hs_timestamp": "2025-02-20T03:30:17.883Z" }, - "createdAt": "2025-02-18T08:46:39.901Z", - "updatedAt": "2025-02-18T08:46:39.901Z", - "archived": false + createdAt: "2025-02-18T08:46:39.901Z", + updatedAt: "2025-02-18T08:46:39.901Z", + archived: false }; return response; @@ -240,11 +240,11 @@ http:Service mockService = service object { } else { BatchResponseSimplePublicObject response = { - "status": "COMPLETE", - "results": [ + status: "COMPLETE", + results: [ { - "id": "77255875305", - "properties": { + id: "77255875305", + properties: { "hs_body_preview": "test batch task body2", "hs_body_preview_html": "\n \n \n test batch task body2\n \n", "hs_body_preview_is_truncated": "false", @@ -274,14 +274,13 @@ http:Service mockService = service object { "hs_task_type": "TODO", "hs_timestamp": "2025-10-30T03:30:17.883Z" }, - "createdAt": "2025-02-18T09:09:19.978Z", - "updatedAt": "2025-02-18T09:09:19.978Z", - "archived": false, - "objectWriteTraceId": "string1" + createdAt: "2025-02-18T09:09:19.978Z", + updatedAt: "2025-02-18T09:09:19.978Z", + archived: false }, { - "id": "77255875304", - "properties": { + id: "77255875304", + properties: { "hs_body_preview": "test batch task body1", "hs_body_preview_html": "\n \n \n test batch task body1\n \n", "hs_body_preview_is_truncated": "false", @@ -311,14 +310,13 @@ http:Service mockService = service object { "hs_task_type": "TODO", "hs_timestamp": "2025-10-30T03:30:17.883Z" }, - "createdAt": "2025-02-18T09:09:19.978Z", - "updatedAt": "2025-02-18T09:09:19.978Z", - "archived": false, - "objectWriteTraceId": "string2" + createdAt: "2025-02-18T09:09:19.978Z", + updatedAt: "2025-02-18T09:09:19.978Z", + archived: false } ], - "startedAt": "2025-02-18T09:09:19.945Z", - "completedAt": "2025-02-18T09:09:20.262Z" + startedAt: "2025-02-18T09:09:19.945Z", + completedAt: "2025-02-18T09:09:20.262Z" }; return response; } @@ -333,18 +331,18 @@ http:Service mockService = service object { # http:DefaultStatusCodeResponse (An error occurred.) resource function post batch/read(@http:Payload BatchReadInputSimplePublicObjectId payload, boolean archived = false) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error { BatchResponseSimplePublicObject response = { - "status": "COMPLETE", - "results": [ + status: "COMPLETE", + results: [ { - "id": "77255886563", - "properties": { + id: "77255886563", + properties: { "hs_createdate": "2025-02-18T09:36:22.519Z", "hs_lastmodifieddate": "2025-02-18T09:36:23.070Z", "hs_object_id": "77255886563", "hs_task_status": "NOT_STARTED", "hs_task_subject": "Batch task1" }, - "propertiesWithHistory": { + propertiesWithHistory: { "hs_task_body": [ { "value": "Sample task body", @@ -362,20 +360,20 @@ http:Service mockService = service object { } ] }, - "createdAt": "2025-02-18T09:36:22.519Z", - "updatedAt": "2025-02-18T09:36:23.070Z", - "archived": false + createdAt: "2025-02-18T09:36:22.519Z", + updatedAt: "2025-02-18T09:36:23.070Z", + archived: false }, { - "id": "77606927069", - "properties": { + id: "77606927069", + properties: { "hs_createdate": "2025-02-18T09:36:57.705Z", "hs_lastmodifieddate": "2025-02-18T09:36:58.197Z", "hs_object_id": "77606927069", "hs_task_status": "NOT_STARTED", "hs_task_subject": "Batch task2" }, - "propertiesWithHistory": { + propertiesWithHistory: { "hs_task_body": [ { "value": "Sample task body", @@ -393,13 +391,13 @@ http:Service mockService = service object { } ] }, - "createdAt": "2025-02-18T09:36:57.705Z", - "updatedAt": "2025-02-18T09:36:58.197Z", - "archived": false + createdAt: "2025-02-18T09:36:57.705Z", + updatedAt: "2025-02-18T09:36:58.197Z", + archived: false } ], - "startedAt": "2025-02-18T09:38:53.032Z", - "completedAt": "2025-02-18T09:38:53.039Z" + startedAt: "2025-02-18T09:38:53.032Z", + completedAt: "2025-02-18T09:38:53.039Z" }; return response; } @@ -412,11 +410,11 @@ http:Service mockService = service object { # http:DefaultStatusCodeResponse (An error occurred.) resource function post batch/update(@http:Payload BatchInputSimplePublicObjectBatchInput payload) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error { BatchResponseSimplePublicObject response = { - "status": "COMPLETE", - "results": [ + status: "COMPLETE", + results: [ { - "id": "77195047646", - "properties": { + id: "77195047646", + properties: { "hs_createdate": "2025-02-17T17:13:54.986Z", "hs_lastmodifieddate": "2025-02-17T17:30:25.243Z", "hs_object_id": "77195047646", @@ -427,14 +425,13 @@ http:Service mockService = service object { "hs_pipeline_stage": "dd5826e4-c976-4654-a527-b59ada542e52", "hs_task_subject": "Updating with test batch update2" }, - "createdAt": "2025-02-17T17:13:54.986Z", - "updatedAt": "2025-02-17T17:30:25.243Z", - "archived": false, - "objectWriteTraceId": "string2" + createdAt: "2025-02-17T17:13:54.986Z", + updatedAt: "2025-02-17T17:30:25.243Z", + archived: false }, { - "id": "77200500438", - "properties": { + id: "77200500438", + properties: { "hs_createdate": "2025-02-17T16:38:28.765Z", "hs_lastmodifieddate": "2025-02-17T17:30:25.244Z", "hs_object_id": "77200500438", @@ -445,14 +442,14 @@ http:Service mockService = service object { "hs_pipeline_stage": "dd5826e4-c976-4654-a527-b59ada542e52", "hs_task_subject": "Updating with test batch update1" }, - "createdAt": "2025-02-17T16:38:28.765Z", - "updatedAt": "2025-02-17T17:30:25.244Z", - "archived": false, - "objectWriteTraceId": "string1" + createdAt: "2025-02-17T16:38:28.765Z", + updatedAt: "2025-02-17T17:30:25.244Z", + archived: false + } ], - "startedAt": "2025-02-18T09:47:19.539Z", - "completedAt": "2025-02-18T09:47:19.621Z" + startedAt: "2025-02-18T09:47:19.539Z", + completedAt: "2025-02-18T09:47:19.621Z" }; return response; } @@ -473,33 +470,33 @@ http:Service mockService = service object { # http:DefaultStatusCodeResponse (An error occurred.) resource function post search(@http:Payload PublicObjectSearchRequest payload) returns CollectionResponseWithTotalSimplePublicObjectForwardPaging|error { CollectionResponseWithTotalSimplePublicObjectForwardPaging response = { - "total": 2, - "results": [ + total: 2, + results: [ { - "id": "76578958019", - "properties": { + id: "76578958019", + properties: { "hs_createdate": "2025-02-16T12:15:45.113Z", "hs_lastmodifieddate": "2025-02-16T12:15:45.724Z", "hs_object_id": "76578958019", "hs_task_body": "a task without associations", "hs_task_status": "NOT_STARTED" }, - "createdAt": "2025-02-16T12:15:45.113Z", - "updatedAt": "2025-02-16T12:15:45.724Z", - "archived": false + createdAt: "2025-02-16T12:15:45.113Z", + updatedAt: "2025-02-16T12:15:45.724Z", + archived: false }, { - "id": "76798585554", - "properties": { + id: "76798585554", + properties: { "hs_createdate": "2025-02-17T10:52:27.816Z", "hs_lastmodifieddate": "2025-02-17T10:52:28.299Z", "hs_object_id": "76798585554", "hs_task_body": "

", "hs_task_status": "NOT_STARTED" }, - "createdAt": "2025-02-17T10:52:27.816Z", - "updatedAt": "2025-02-17T10:52:28.299Z", - "archived": false + createdAt: "2025-02-17T10:52:27.816Z", + updatedAt: "2025-02-17T10:52:28.299Z", + archived: false } ] }; diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 18900a6..d06b403 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -68,8 +68,8 @@ isolated function testGetTasksById() returns error? { } isolated function testUpdateTask() returns error? { SimplePublicObject response = check taskClient->/[updateTestTaskId].patch(payload = { - "objectWriteTraceId": "string", - "properties": { + objectWriteTraceId: "string", + properties: { "hs_task_subject": updateTestsubject } }); @@ -119,18 +119,18 @@ isolated function testTaskSearch() returns error? { } isolated function testBatchTasksUpdate() returns error? { BatchInputSimplePublicObjectBatchInput batchTaskInput = { - "inputs": [ + inputs: [ { - "objectWriteTraceId": "string1", - "id": "77200500438", - "properties": { + objectWriteTraceId: "string1", + id: "77200500438", + properties: { "hs_task_subject": "Updating with test batch update1" } }, { - "objectWriteTraceId": "string2", - "id": "77195047646", - "properties": { + objectWriteTraceId: "string2", + id: "77195047646", + properties: { "hs_task_subject": "Updating with test batch update2" } } @@ -148,23 +148,23 @@ isolated function testBatchTasksUpdate() returns error? { isolated function testTasksBatchCreate() returns error? { BatchInputSimplePublicObjectInputForCreate batchTaskInput = { - "inputs": [ + inputs: [ { - "associations": [ + associations: [ { - "types": [ + types: [ { - "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": 192 + associationCategory: "HUBSPOT_DEFINED", + associationTypeId: 192 } ], - "to": { - "id": "38349931215" + to: { + id: "38349931215" } } ], - "objectWriteTraceId": "string2", - "properties": { + objectWriteTraceId: "string2", + properties: { "hs_timestamp": "2025-10-30T03:30:17.883Z", "hs_task_body": "test batch task body1", "hs_task_subject": "test batch task subject1", @@ -174,21 +174,21 @@ isolated function testTasksBatchCreate() returns error? } }, { - "associations": [ + associations: [ { - "types": [ + types: [ { - "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": 192 + associationCategory: "HUBSPOT_DEFINED", + associationTypeId: 192 } ], - "to": { - "id": "38349931215" + to: { + id: "38349931215" } } ], - "objectWriteTraceId": "string1", - "properties": { + objectWriteTraceId: "string1", + properties: { "hs_timestamp": "2025-10-30T03:30:17.883Z", "hs_task_body": "test batch task body2", "hs_task_subject": "test batch task subject2", @@ -210,7 +210,7 @@ isolated function testTasksBatchCreate() returns error? groups: ["live_tests", "mock_tests"] } isolated function testTasksBatchArchieve() returns error? { - BatchInputSimplePublicObjectId batchTaskInput = {inputs: [{"id": testBatchTaskArchieveId1}, {"id": testBatchTaskArchieveId2}]}; + BatchInputSimplePublicObjectId batchTaskInput = {inputs: [{id: testBatchTaskArchieveId1}, {id: testBatchTaskArchieveId2}]}; http:Response response = check taskClient->/batch/archive.post(payload = batchTaskInput); test:assertTrue(response.statusCode == 204, msg = "Batch task archieve failed. Please check the input data or server response for issues."); } @@ -220,21 +220,21 @@ isolated function testTasksBatchArchieve() returns error? { } isolated function testTaskCreate() returns error? { SimplePublicObjectInputForCreate taskCreateInput = { - "associations": [ + associations: [ { - "to": { - "id": "84267202257" + to: { + id: "84267202257" }, - "types": [ + types: [ { - "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": 204 + associationCategory: "HUBSPOT_DEFINED", + associationTypeId: 204 } ] } ], - "objectWriteTraceId": "string", - "properties": { + objectWriteTraceId: "string", + properties: { "hs_timestamp": "2025-02-20T03:30:17.883Z", "hs_task_body": "Sample task body", "hs_task_priority": "LOW", @@ -268,21 +268,21 @@ isolated function testGetTasksByInvalidId() returns error?{ isolated function testTaskCreateWithInvalidAssociationToId() returns error? { SimplePublicObjectInputForCreate taskCreateInput = { - "associations": [ + associations: [ { - "to": { - "id": "-1" + to: { + id: "-1" }, - "types": [ + types: [ { - "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": 204 + associationCategory: "HUBSPOT_DEFINED", + associationTypeId: 204 } ] } ], - "objectWriteTraceId": "string", - "properties": { + objectWriteTraceId: "string", + properties: { "hs_timestamp": "2025-02-20T03:30:17.883Z", "hs_task_body": "Sample task body", "hs_task_priority": "LOW", @@ -300,8 +300,8 @@ isolated function testTaskCreateWithInvalidAssociationToId() returns error? isolated function testTaskUpdateWithInvalidId() returns error? { SimplePublicObject|error response = taskClient->/["-1"].patch(payload = { - "objectWriteTraceId": "string", - "properties": { + objectWriteTraceId: "string", + properties: { "hs_task_subject": updateTestsubject } }); @@ -313,23 +313,23 @@ isolated function testTaskUpdateWithInvalidId() returns error? isolated function testTaskBatchCreateWithInvalidAssociationToId() returns error? { BatchInputSimplePublicObjectInputForCreate batchTaskInput = { - "inputs": [ + inputs: [ { - "associations": [ + associations: [ { - "to": { - "id": "-1" + to: { + id: "-1" }, - "types": [ + types: [ { - "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": 204 + associationCategory: "HUBSPOT_DEFINED", + associationTypeId: 204 } ] } ], - "objectWriteTraceId": "string2", - "properties": { + objectWriteTraceId: "string2", + properties: { "hs_timestamp": "2025-10-30T03:30:17.883Z", "hs_task_body": "test batch task body1", "hs_task_subject": "test batch task subject1", @@ -339,12 +339,12 @@ isolated function testTaskBatchCreateWithInvalidAssociationToId() returns error? } }, { - "associations": [ + associations: [ { - "to": { + to: { "id": "-2" }, - "types": [ + types: [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 204 @@ -352,8 +352,8 @@ isolated function testTaskBatchCreateWithInvalidAssociationToId() returns error? ] } ], - "objectWriteTraceId": "string1", - "properties": { + objectWriteTraceId: "string1", + properties: { "hs_timestamp": "2025-10-30T03:30:17.883Z", "hs_task_body": "test batch task body2", "hs_task_subject": "test batch task subject2", From 016176e0c8b8eb9bc1e178f6b4c285e14a70e5dd Mon Sep 17 00:00:00 2001 From: ChathuraIshara Date: Mon, 24 Feb 2025 09:44:40 +0530 Subject: [PATCH 7/7] Remove unused test case and format the test.bal file --- ballerina/tests/test.bal | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index d06b403..12afa12 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -98,11 +98,6 @@ isolated function testTasksBatchRead() returns error? { } } -@test:Config { -} -isolated function testTaskBatchUpsert() returns error? { -} - @test:Config { groups: ["live_tests", "mock_tests"] } @@ -255,6 +250,7 @@ isolated function testTasksGetPage() returns error? { test:assertTrue(response.results.length() > 0, msg = "Failed to retrieve tasks of a page"); } } + @test:Config{ groups: ["live_tests", "mock_tests"] } @@ -262,6 +258,7 @@ isolated function testGetTasksByInvalidId() returns error?{ SimplePublicObject|error response = taskClient->/["-1"]; test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); } + @test:Config{ groups: ["live_tests", "mock_tests"] } @@ -307,6 +304,7 @@ isolated function testTaskUpdateWithInvalidId() returns error? }); test:assertTrue(response is error,msg="Expected an error response for invalid taskId"); } + @test:Config{ groups: ["live_tests", "mock_tests"] }