Skip to content

Commit

Permalink
Merge pull request #4 from ThisaraWeerakoon/main
Browse files Browse the repository at this point in the history
Edit test files to run only the mock tests and included the suggested changes for examples
  • Loading branch information
MohamedSabthar authored Jan 17, 2025
2 parents 267cefa + 506a3d0 commit 3588eb5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0"
distribution-version = "2201.10.3"

[[package]]
org = "ballerina"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tests/mock_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ballerina/http;

service on new http:Listener(9090) {

resource function post crm/v3/objects/meetings/batch/upsert(@http:Payload BatchInputSimplePublicObjectBatchInputUpsert payload) returns BatchResponseSimplePublicUpsertObject{
resource function post crm/v3/objects/meetings/batch/upsert(@http:Payload BatchInputSimplePublicObjectBatchInputUpsert payload) returns BatchResponseSimplePublicUpsertObject {
return {
completedAt: "2025-01-07T08:47:48.319Z",
"requestedAt": "2025-01-07T08:47:48.319Z",
Expand Down
8 changes: 4 additions & 4 deletions ballerina/tests/mock_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final Client meetingClient = check new (
);

@test:Config {
groups: ["mock_tests"]
groups: ["mock_service_test"]
}
function testMockUpsertBatch() returns error? {
BatchInputSimplePublicObjectBatchInputUpsert payload = {
Expand All @@ -38,21 +38,21 @@ function testMockUpsertBatch() returns error? {
}
]
};
BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors response =
BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors response =
check meetingClient->/batch/upsert.post(payload);
test:assertTrue(response.status is "COMPLETE");
}

@test:Config {
groups: ["mock_tests"]
groups: ["mock_service_test"]
}
function testMockGetMeetings() returns error? {
CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check meetingClient->/;
test:assertTrue(response.results.length() > 0);
}

@test:Config {
groups: ["mock_tests"]
groups: ["mock_service_test"]
}
function testMockCreateMeeting() returns error? {
SimplePublicObjectInputForCreate payload = {
Expand Down
49 changes: 26 additions & 23 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@ import ballerina/http;
import ballerina/oauth2;
import ballerina/test;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string serviceUrl = ?;
configurable string clientId = "clientId";
configurable string clientSecret = "clientSecret";
configurable string refreshToken = "refreshToken";
configurable boolean enableClientOauth2 = false;

OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
// create connection config for live client
ConnectionConfig config = {
auth: enableClientOauth2 ? {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
} : {token: "Bearer token"}
};

ConnectionConfig config = {auth: auth};
final Client hubspot = check new Client(config, serviceUrl);
// create live client
final Client hubspot = check new Client(config);
// keep the meeting id as reference for other tests after creation
string meetingId = "";
// keep the meeting batch id as reference for other tests after creation
string meetingBatchId = "";

@test:Config {
dependsOn: [testUpdateMeeting],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testArchiveMeeting() returns error? {
http:Response response = check hubspot->/[meetingId].delete();
Expand All @@ -48,7 +51,7 @@ function testArchiveMeeting() returns error? {

@test:Config {
dependsOn: [testgetMeetingById],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testUpdateMeeting() returns error? {
SimplePublicObjectInput payload = {
Expand All @@ -62,7 +65,7 @@ function testUpdateMeeting() returns error? {

@test:Config {
dependsOn: [testCreateMeeting],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testgetMeetingById() returns error? {
SimplePublicObjectWithAssociations meeting = check hubspot->/[meetingId]();
Expand All @@ -71,7 +74,7 @@ function testgetMeetingById() returns error? {

@test:Config {
dependsOn: [testgetBatchById],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testUpdateBatch() returns error? {
BatchInputSimplePublicObjectBatchInput payload = {
Expand All @@ -88,7 +91,7 @@ function testUpdateBatch() returns error? {

@test:Config {
dependsOn: [testCreateBatch],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testgetBatchById() returns error? {
BatchReadInputSimplePublicObjectId payload =
Expand All @@ -107,7 +110,7 @@ function testgetBatchById() returns error? {

@test:Config {
dependsOn: [testgetBatchById],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testArchiveBatch() returns error? {
BatchInputSimplePublicObjectId payload = {
Expand All @@ -121,8 +124,8 @@ function testArchiveBatch() returns error? {
test:assertTrue(response.statusCode == 204);
}

@test:Config{
groups: ["live_tests"]
@test:Config {
groups: ["live_service_test"]
}
function testCreateMeeting() returns error? {
SimplePublicObjectInputForCreate payload = {
Expand All @@ -139,15 +142,15 @@ function testCreateMeeting() returns error? {

@test:Config {
dependsOn: [testCreateMeeting],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testgetAllMeetings() returns error? {
CollectionResponseSimplePublicObjectWithAssociationsForwardPaging meetings = check hubspot->/;
test:assertTrue(meetings.results.length() > 0);
};

@test:Config{
groups: ["live_tests"]
@test:Config {
groups: ["live_service_test"]
}
function testCreateBatch() returns error? {
BatchInputSimplePublicObjectInputForCreate payload = {
Expand All @@ -165,7 +168,7 @@ function testCreateBatch() returns error? {

@test:Config {
dependsOn: [testgetAllMeetings],
groups: ["live_tests"]
groups: ["live_service_test"]
}
function testSearchMeetings() returns error? {
PublicObjectSearchRequest query = {
Expand Down
22 changes: 11 additions & 11 deletions examples/Meeting_batch/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
// specific language governing permissions and limitations
// under the License.

import ballerinax/hubspot.crm.engagement.meeting as meeting;
import ballerina/http;
import ballerina/io;
import ballerina/oauth2;
import ballerinax/hubspot.crm.engagement.meeting as hsmeeting;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string serviceUrl = ?;

meeting:OAuth2RefreshTokenGrantConfig auth = {
hsmeeting:OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
Expand All @@ -33,23 +33,23 @@ meeting:OAuth2RefreshTokenGrantConfig auth = {

public function main() returns error? {
string meetingId = "";
final meeting:Client meetingClient = check new ({auth});
final hsmeeting:Client meetingClient = check new ({auth});

//create a meeting batch
meeting:BatchInputSimplePublicObjectInputForCreate createBatchPayload = {
hsmeeting:BatchInputSimplePublicObjectInputForCreate createBatchPayload = {
"inputs": [
{
"properties": {},
"associations": []
}
]
};
meeting:BatchResponseSimplePublicObject meetingResponse = check meetingClient->/batch/create.post(createBatchPayload);
hsmeeting:BatchResponseSimplePublicObject meetingResponse = check meetingClient->/batch/create.post(createBatchPayload);
meetingId = meetingResponse.results[0].id;
io:println(`A meeting batch created with id ${meetingId}`);

//get created meeting batch by id
meeting:BatchReadInputSimplePublicObjectId payload =
hsmeeting:BatchReadInputSimplePublicObjectId payload =
{
"propertiesWithHistory": [],
"inputs": [
Expand All @@ -61,11 +61,11 @@ public function main() returns error? {
"hs_timestamp"
]
};
meeting:BatchResponseSimplePublicObject|meeting:BatchResponseSimplePublicObjectWithErrors meetingOutput = check meetingClient->/batch/read.post(payload);
hsmeeting:BatchResponseSimplePublicObject|hsmeeting:BatchResponseSimplePublicObjectWithErrors meetingOutput = check meetingClient->/batch/read.post(payload);
io:println(`Created Meeting batch id: ${meetingOutput.results[0].id} and scheduled date ${meetingOutput.results[0].properties["hs_timestamp"]}`);

//update created meeting batch scheduled date
meeting:BatchInputSimplePublicObjectBatchInput updatePayload = {
hsmeeting:BatchInputSimplePublicObjectBatchInput updatePayload = {
"inputs": [
{
"id": meetingId,
Expand All @@ -75,18 +75,18 @@ public function main() returns error? {
}
]
};
meeting:BatchResponseSimplePublicObject|meeting:BatchResponseSimplePublicObjectWithErrors response = check meetingClient->/batch/update.post(updatePayload);
hsmeeting:BatchResponseSimplePublicObject|hsmeeting:BatchResponseSimplePublicObjectWithErrors _ = check meetingClient->/batch/update.post(updatePayload);
io:println(`Meeting batch updated with id ${meetingId}`);

//archive created meeting batch
meeting:BatchInputSimplePublicObjectId archivePayload = {
hsmeeting:BatchInputSimplePublicObjectId archivePayload = {
"inputs": [
{
"id": meetingId
}
]
};
http:Response archiveResponse = check meetingClient->/batch/archive.post(archivePayload);
http:Response _ = check meetingClient->/batch/archive.post(archivePayload);
io:println(`Meeting batch archived with id ${meetingId}`);

}
Expand Down
18 changes: 9 additions & 9 deletions examples/Meeting_for_contacts/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
// specific language governing permissions and limitations
// under the License.

import ballerinax/hubspot.crm.engagement.meeting as meeting;
import ballerina/http;
import ballerina/io;
import ballerina/oauth2;
import ballerinax/hubspot.crm.engagement.meeting as hsmeeting;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string serviceUrl = ?;
configurable string contactId = ?;

meeting:OAuth2RefreshTokenGrantConfig auth = {
hsmeeting:OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
};

public function main() returns error? {
final meeting:Client meetingClient = check new ({auth});
final hsmeeting:Client meetingClient = check new ({auth});

//create a meeting associated with the contact
meeting:SimplePublicObjectInputForCreate createPayload = {
hsmeeting:SimplePublicObjectInputForCreate createPayload = {
"properties": {
"hs_timestamp": "2025-03-23T01:02:44.872Z",
"hs_meeting_title": "Intro meeting",
Expand All @@ -63,26 +63,26 @@ public function main() returns error? {
]

};
meeting:SimplePublicObject meetingResponse = check meetingClient->/.post(createPayload);
hsmeeting:SimplePublicObject meetingResponse = check meetingClient->/.post(createPayload);
string meetingId = meetingResponse.id;
io:println(`A meeting created associated to the contact (contactId:${contactId}) with id ${meetingId}`);

//get created meeting by id
meeting:SimplePublicObjectWithAssociations meetingOutput = check meetingClient->/[meetingId]();
hsmeeting:SimplePublicObjectWithAssociations meetingOutput = check meetingClient->/[meetingId]();
io:println(`Created Meeting title: ${meetingOutput.properties["hs_meeting_title"]} and scheduled date ${meetingOutput.properties["hs_timestamp"]}`);

//update created meeting scheduled date and titile
meeting:SimplePublicObjectInput updatePayload = {
hsmeeting:SimplePublicObjectInput updatePayload = {
"properties": {
"hs_timestamp": "2025-05-23T01:02:44.872Z",
"hs_meeting_title": "Intro meeting updated"
}
};
meeting:SimplePublicObject updatedOutput = check meetingClient->/[meetingId].patch(updatePayload);
hsmeeting:SimplePublicObject updatedOutput = check meetingClient->/[meetingId].patch(updatePayload);
io:println(`Meeting updated with title ${updatedOutput.properties["hs_meeting_title"]} and scheduled date ${updatedOutput.properties["hs_timestamp"]}`);

//get all meetings associated with the contact
meeting:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging meetingList = check meetingClient->/;
hsmeeting:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging meetingList = check meetingClient->/;
io:println(`Meetings associated with the contact: ${meetingList.toBalString()}`);

//delete the created meeting
Expand Down

0 comments on commit 3588eb5

Please sign in to comment.