Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]
modules = [
{org = "ballerina", packageName = "io", moduleName = "io"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -320,6 +323,7 @@ name = "hubspot.marketing.campaigns"
version = "1.0.0"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
144 changes: 99 additions & 45 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/io;
import ballerina/oauth2;
import ballerina/test;
import ballerina/time;
Expand All @@ -33,135 +34,188 @@ OAuth2RefreshTokenGrantConfig authConfig = {

ConnectionConfig config = {auth: authConfig};

final Client baseClient = check new Client(config, serviceUrl = serviceUrl);
final Client baseClient = check new Client(config);

//Variables
string campaignGuid2 = "" ;
string campaignGuid2 = "";
configurable string campaignGuid = ?;
configurable string assetType = ?;
configurable string assetID = ?;
//string[] currencyCodes = ["USD", "EUR", "GBP", "JPY", "AUD", "CAD", "CHF", "CNY", "SEK", "NZD"];

configurable string sampleCampaignGuid1 = ?;
configurable string sampleCampaignGuid2 = ?;
configurable string sampleCampaignGuid3 = ?;
configurable string sampleCampaignGuid4 = ?;


//SearchMarketingCampaigns
@test:Config {}
isolated function testGetSearchMarketingCampaigns() returns error? {
CollectionResponseWithTotalPublicCampaignForwardPaging response = check baseClient->/.get();
test:assertTrue(response?.results.length() > 0);
}

//CreateMarketingCampaigns
@test:Config {}
function testPostCreateMarketingCampaigns() returns error? {
PublicCampaign response = check baseClient->/.post(
payload = {properties: {
"hs_name": "campaign" + time:utcNow().toString() ,
"hs_goal": "campaignGoalSpecified",
"hs_notes": "someNotesForTheCampaign"
}}
payload = {
properties: {
"hs_name": "campaign" + time:utcNow().toString(),
"hs_goal": "campaignGoalSpecified",
"hs_notes": "someNotesForTheCampaign"
}
}
);
test:assertTrue(response?.id != "");
test:assertNotEquals(response?.id , "");
campaignGuid2 = response?.id;
}

//Read a Marketing Campaign
@test:Config {}
isolated function testGetReadACampaign() returns error? {
PublicCampaignWithAssets response = check baseClient->/[campaignGuid];
test:assertTrue(response?.id == campaignGuid);
test:assertEquals(response?.id , campaignGuid);
}

//Update a Marketing Campaign
@test:Config {}
isolated function testPatchUpdateCampaigns() returns error? {
PublicCampaign response = check baseClient->/[campaignGuid].patch(
payload = {properties: {
"hs_goal": "updatedCampaignGoal",
"hs_notes": "updatedNotesForTheCampaign"
}}
payload = {
properties: {
"hs_goal": "updatedCampaignGoal",
"hs_notes": "updatedNotesForTheCampaign"
}
}
);
test:assertTrue(response?.id == campaignGuid);
test:assertEquals(response?.id , campaignGuid);
}

//Create a Batch of Marketing Campaigns
@test:Config {}
isolated function testPostBatchCreate() returns error? {
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check baseClient->/batch/create.post(
payload = {
"inputs": [
{
"properties": {
"hs_name": "batchCampaign" + time:utcToString(time:utcNow()),
"hs_goal": "batchCampaignGoalSpecified"
}
"inputs": [
{
"properties": {
"hs_name": "batchCampaign" + time:utcToString(time:utcNow()),
"hs_goal": "batchCampaignGoalSpecified"
}
]
}
}
]
}
);
test:assertTrue(response?.status == "COMPLETE");
test:assertEquals(response?.status , "COMPLETE");
}

//Update a Batch of Marketing Campaigns
@test:Config {}
isolated function testPostBatchRead() returns error? {
BatchResponsePublicCampaignWithAssets|BatchResponsePublicCampaignWithAssetsWithErrors response = check baseClient->/batch/read.post(
isolated function testPostBatchUpdate() returns error? {
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check baseClient->/batch/update.post(
payload = {
"inputs": [
{
"id": "ef46bced-1a75-42b5-9f5f-ebdd39cbfd3b"
"inputs": [
{
"id": sampleCampaignGuid1,
"properties": {
"hs_goal": "updatedGoal",
"hs_notes": "updatedNote"
}
]
}
}
]
}
);
test:assertTrue(response?.status == "COMPLETE");
test:assertEquals(response?.status , "COMPLETE");
}

//Read a Batch of Marketing Campaigns
@test:Config {}
isolated function testPostBatchRead() returns error? {
BatchResponsePublicCampaignWithAssets|BatchResponsePublicCampaignWithAssetsWithErrors response = check baseClient->/batch/read.post(
payload = {
"inputs": [
{
"id": sampleCampaignGuid2
}
]
}
);
test:assertEquals(response?.status , "COMPLETE");
}

//Get Reports - Revenue
@test:Config {}
isolated function testGetReportsRevenue() returns error? {
RevenueAttributionAggregate response = check baseClient->/[campaignGuid]/reports/revenue;
test:assertTrue(response?.revenueAmount is decimal);
}

//Reports Metrics
@test:Config {}
isolated function testGetReportsMetrics() returns error? {
MetricsCounters response = check baseClient->/[campaignGuid]/reports/metrics;
test:assertTrue(response?.sessions == 0);
test:assertTrue(response?.sessions >= 0);
}

//List Assets Associated with a Campaign
@test:Config {}
isolated function testGetListAssets() returns error? {
isolated function testGetListAssets() returns error? {
CollectionResponsePublicCampaignAssetForwardPaging response = check baseClient->/[campaignGuid]/assets/[assetType];
test:assertTrue(response?.results.length() > 0);

}

@test:Config {}
isolated function testPutAddAssetAssociation() returns error? {
//Add an Asset Association to a Campaign
@test:Config {
dependsOn: [testDeleteRemoveAssetAssociation]
}
isolated function testPutAddAssetAssociation() returns error? {
var response = check baseClient->/[campaignGuid]/assets/[assetType]/[assetID].put();
test:assertTrue(response.statusCode == 204);
test:assertEquals(response.statusCode , 204);
}

//Remove an Asset Association from a Campaign
@test:Config {
dependsOn: [testPutAddAssetAssociation, testGetListAssets]
dependsOn: [testGetListAssets]
}
isolated function testDeleteRemoveAssetAssociation() returns error? {
isolated function testDeleteRemoveAssetAssociation() returns error? {
var response = check baseClient->/[campaignGuid]/assets/[assetType]/[assetID].delete();
test:assertTrue(response.statusCode == 204);
test:assertEquals(response.statusCode , 204);
}

//Read Budget
@test:Config {}
isolated function testGetReadBudget() returns error? {
PublicBudgetTotals response = check baseClient->/[campaignGuid]/budget/totals;
io:println(response);
test:assertTrue(response.currencyCode == "USD");
}

//Delete a Marketing Campaign
@test:Config {
dependsOn: [testPostCreateMarketingCampaigns]
}
function testDeleteCampaign() returns error? {
function testDeleteCampaign() returns error? {
var response = check baseClient->/[campaignGuid2].delete();
test:assertTrue(response.statusCode == 204);
test:assertEquals(response.statusCode , 204);
}

//Delete a Batch of Marketing Campaigns
@test:Config {}
isolated function testPostDeleteABatchOfCampaigns() returns error? {
var response = check baseClient->/batch/archive.post(
payload = {
"inputs": [
{
"id": "b3e493b0-9d5a-4b3e-a362-f4e0f015345d"
"id": sampleCampaignGuid3
},
{
"id": "96a87dab-554a-474c-853b-c78193a8b889"
"id": sampleCampaignGuid4
}
]
}
);
test:assertTrue(response.statusCode == 204);
test:assertEquals(response.statusCode , 204);
}