Skip to content

Commit

Permalink
Merge pull request #5 from harithmaduranga/main
Browse files Browse the repository at this point in the history
Fix issues in test config
  • Loading branch information
MohamedSabthar authored Jan 17, 2025
2 parents 52a13f2 + b8928c8 commit 1ecf07d
Showing 1 changed file with 44 additions and 46 deletions.
90 changes: 44 additions & 46 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import ballerina/oauth2;
import ballerina/test;

configurable string clientId = "clientId";
configurable string clientSecret ="clientSecret";
configurable string clientSecret = "clientSecret";
configurable string refreshToken = "refreshToken";
configurable boolean enableLiveServerTest = false;

OAuth2RefreshTokenGrantConfig auth = {
clientId,
Expand All @@ -29,22 +30,23 @@ OAuth2RefreshTokenGrantConfig auth = {
credentialBearer: oauth2:POST_BODY_BEARER
};

final Client hubspotClient = check new ({auth});
final Client hubspotClient = check new ({
auth: enableLiveServerTest ? auth
: {token: "test-token"}
});

string testQuoteId = "";

boolean enableLiveServerTest = false;

// Test function for creating a quote
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testCreateNewQuote() returns error? {
SimplePublicObjectInputForCreate payload = {
associations: [],
properties: {
"hs_title": "Test Quote",
"hs_title": "Test Quote",
"hs_expiration_date": "2025-01-31"
}
};
Expand All @@ -56,14 +58,13 @@ function testCreateNewQuote() returns error? {
testQuoteId = response.id;

// Validate the response
test:assertEquals(response.properties["hs_title"], "Test Quote",
"New quote not created successfully.");

}
test:assertEquals(response.properties["hs_title"], "Test Quote",
"New quote not created successfully.");

}

// Test function for creating a batch of quotes
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
Expand All @@ -72,48 +73,47 @@ function testCreateNewBatchOfQuotes() returns error? {
SimplePublicObjectInputForCreate batchInput1 = {
associations: [],
properties: {
"hs_title": "Test Quote 1",
"hs_title": "Test Quote 1",
"hs_expiration_date": "2025-02-28"
}
};

SimplePublicObjectInputForCreate batchInput2 = {
associations: [],
properties: {
"hs_title": "Test Quote 2",
"hs_title": "Test Quote 2",
"hs_expiration_date": "2025-04-30"
}
};

BatchInputSimplePublicObjectInputForCreate payload = {
inputs: [batchInput1, batchInput2]
inputs: [batchInput1, batchInput2]
};

// Call the Quotes API to create a new quote
BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors response = check hubspotClient->/batch/create.post(payload);

// Validate the response
test:assertEquals(response.results.length(), payload.inputs.length(),
"New batch of quotes not created successfully.");

}
test:assertEquals(response.results.length(), payload.inputs.length(),
"New batch of quotes not created successfully.");

}

// Test for retrieving all quotes
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testGetAllQuotes() returns error? {

CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response = check hubspotClient->/.get();

test:assertTrue(response.results.length() > 0,
msg = "No quotes found in the response.");
test:assertTrue(response.results.length() > 0,
msg = "No quotes found in the response.");
}

// Test function for retrieving a quote
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
Expand All @@ -124,84 +124,82 @@ function testGetOneQuote() returns error? {
}

// Test function for retrieving a batch of quotes
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testGetBatchOfQuotes() returns error? {

SimplePublicObjectId batchInput0 = {
id: testQuoteId
id: testQuoteId
};

BatchReadInputSimplePublicObjectId payload = {
properties: [],
propertiesWithHistory: [],
propertiesWithHistory: [],
inputs: [batchInput0]
};

BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors response = check hubspotClient->/batch/read.post(payload);

// Validate essential fields
test:assertEquals(response.results.length(), payload.inputs.length(), msg = string`Only ${response.results.length()} IDs found.`);
}

test:assertEquals(response.results.length(), payload.inputs.length(), msg = string `Only ${response.results.length()} IDs found.`);
}

// Archive a quote by ID
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testArchiveOneQuote() returns error?{
function testArchiveOneQuote() returns error? {

http:Response response = check hubspotClient->/["0"].delete();
http:Response response = check hubspotClient->/["0"].delete();

test:assertTrue(response.statusCode == 204);
}

// Archive batch of quotes by ID
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testArchiveBatchOfQuoteById() returns error?{
function testArchiveBatchOfQuoteById() returns error? {

SimplePublicObjectId id0 = {id:"0"};
SimplePublicObjectId id0 = {id: "0"};

BatchInputSimplePublicObjectId payload = {
inputs:[
id0
inputs: [
id0
]
};

http:Response response = check hubspotClient->/batch/archive.post(payload);
http:Response response = check hubspotClient->/batch/archive.post(payload);

test:assertTrue(response.statusCode == 204);
}


// Test function for updating a quote
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
function testUpdateOneQuote() returns error? {
SimplePublicObjectInput payload = {
properties: {
"hs_title": "Test Quote Modified",
"hs_expiration_date": "2025-03-31"
"hs_expiration_date": "2025-03-31"
}
};

// Call the Quotes API to update the quote
SimplePublicObject response = check hubspotClient->/[testQuoteId].patch(payload);

test:assertEquals(response.properties["hs_title"], "Test Quote Modified",
"Quote not updated successfully.");
test:assertEquals(response.properties["hs_title"], "Test Quote Modified",
"Quote not updated successfully.");
}

// Test function for updating a batch of quotes
@test:Config{
@test:Config {
groups: ["live_tests"],
enable: enableLiveServerTest
}
Expand All @@ -210,7 +208,7 @@ function testUpdateBatchOfQuotes() returns error? {
SimplePublicObjectBatchInput batchInput3 = {
id: testQuoteId,
properties: {
"hs_title": "Test Quote 3",
"hs_title": "Test Quote 3",
"hs_expiration_date": "2025-04-30"
}
};
Expand All @@ -222,7 +220,7 @@ function testUpdateBatchOfQuotes() returns error? {
// Call the Quotes API to create a new quote
BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors response = check hubspotClient->/batch/update.post(payload);

test:assertEquals(response.results.length(), payload.inputs.length(),
"Quote in response does not match the expected quote.");
test:assertEquals(response.results.length(), payload.inputs.length(),
"Quote in response does not match the expected quote.");
}

0 comments on commit 1ecf07d

Please sign in to comment.