Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Live test file #5

Merged
merged 10 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ final hsmcampaigns:ConnectionConfig hsmcampaignsConfig = {
}
};

final hsmcampaigns:Client hsmcampaignsClient = check new (hsmcampaignsConfig);
final hsmcampaigns:Client hsmCampaignsClient = check new (hsmcampaignsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -175,7 +175,7 @@ Retrieve a Marketing Campaign

```ballerina
public function main() returns error? {
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmcampaignsClient->/marketing/v3/campaigns.get();
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmCampaignsClient->/marketing/v3/campaigns.get();
}
```

Expand Down
6 changes: 5 additions & 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.3"
distribution-version = "2201.10.0"

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

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -325,6 +328,7 @@ dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "oauth2"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"},
Expand Down
4 changes: 2 additions & 2 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ final hsmcampaigns:ConnectionConfig hsmcampaignsConfig = {
}
};

final hsmcampaigns:Client hsmcampaignsClient = check new (hsmcampaignsConfig);
final hsmcampaigns:Client hsmCampaignsClient = check new (hsmcampaignsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -167,7 +167,7 @@ Retrieve a Marketing Campaign

```ballerina
public function main() returns error? {
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmcampaignsClient->/marketing/v3/campaigns.get();
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmCampaignsClient->/marketing/v3/campaigns.get();
}
```

Expand Down
4 changes: 2 additions & 2 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ final hsmcampaigns:ConnectionConfig hsmcampaignsConfig = {
}
};

final hsmcampaigns:Client hsmcampaignsClient = check new (hsmcampaignsConfig);
final hsmcampaigns:Client hsmCampaignsClient = check new (hsmcampaignsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -168,7 +168,7 @@ Retrieve a Marketing Campaign

```ballerina
public function main() returns error? {
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmcampaignsClient->/marketing/v3/campaigns.get();
hsmcampaigns:CollectionResponseWithTotalPublicCampaignForwardPaging campaigns = check hsmCampaignsClient->/marketing/v3/campaigns.get();
}
```

Expand Down
12 changes: 9 additions & 3 deletions ballerina/tests/mock_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

import ballerina/test;

final Client mockClient = check new (config, serviceUrl = "http://localhost:8080/marketing/v3/campaigns");
final Client mockClient = check new (
{
auth: {
token: "test-token" // This approach eliminates the need for the client to make additional server requests for token validation, such as a refresh token request in the OAuth2 flow.
}
}, "http://localhost:9090/marketing/v3/campaigns"
);

final string campaignMockGuid = "c4573779-0830-4eb3-bfa3-0916bda9c1a4";
final string assetMockType = "FORM";
Expand All @@ -41,14 +47,14 @@ isolated function mockTestCreateCampaign() returns error? {
groups: ["mock_tests"]
}
isolated function testMockGetReadCampaign() returns error? {
PublicCampaignWithAssets response = check baseClient->/[campaignMockGuid];
PublicCampaignWithAssets response = check mockClient->/[campaignMockGuid];
test:assertEquals(response?.id, campaignGuid);
}

@test:Config {
groups: ["mock_tests"]
}
isolated function testMockGetListAssets() returns error? {
CollectionResponsePublicCampaignAssetForwardPaging response = check baseClient->/[campaignMockGuid]/assets/[assetMockType];
CollectionResponsePublicCampaignAssetForwardPaging response = check mockClient->/[campaignMockGuid]/assets/[assetMockType];
test:assertTrue(response?.results.length() > 0);
}
101 changes: 59 additions & 42 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
// under the License.

import ballerina/oauth2;
import ballerina/os;
import ballerina/test;
import ballerina/time;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable boolean enableClient0auth2 = os:getEnv("IS_LIVE_SERVER") == "false";
configurable string clientId = enableClient0auth2 ? os:getEnv("CLIENT_ID") : "test";
configurable string clientSecret = enableClient0auth2 ? os:getEnv("CLIENT_SECRET") : "test";
configurable string refreshToken = enableClient0auth2 ? os:getEnv("REFRESH_TOKEN") : "test";

// configurable string clientId = ?;
// configurable string clientSecret = ?;
// configurable string refreshToken = ?;
ThisaruGuruge marked this conversation as resolved.
Show resolved Hide resolved

OAuth2RefreshTokenGrantConfig auth = {
clientId,
Expand All @@ -29,33 +35,32 @@ OAuth2RefreshTokenGrantConfig auth = {
credentialBearer: oauth2:POST_BODY_BEARER
};

ConnectionConfig config = {auth};

final Client baseClient = check new (config);
final Client hsmCampaignsClient = check new ({auth: enableClient0auth2 ? auth : {token: "Bearer token"}});

string campaignGuid2 = "";
configurable string campaignGuid = ?;
configurable string assetType = ?;
configurable string assetID = ?;

configurable string sampleCampaignGuid1 = ?;
configurable string sampleCampaignGuid2 = ?;
configurable string sampleCampaignGuid3 = ?;
configurable string sampleCampaignGuid4 = ?;
final string campaignGuid = "c4573779-0830-4eb3-bfa3-0916bda9c1a4";
final string assetType = "FORM";
final string assetID = "88047023-7777-40a1-b74b-4b1139e8d45b";
final string sampleCampaignGuid1 = "ab04d4a6-1469-4ab0-9128-07bfc1b472e8";
final string sampleCampaignGuid2 = "ef46bced-1a75-42b5-9f5f-ebdd39cbfd3b";
final string sampleCampaignGuid3 = "b3e493b0-9d5a-4b3e-a362-f4e0f015345d";
final string sampleCampaignGuid4 = "96a87dab-554a-474c-853b-c78193a8b889";

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testGetSearchMarketingCampaigns() returns error? {
CollectionResponseWithTotalPublicCampaignForwardPaging response = check baseClient->/.get();
CollectionResponseWithTotalPublicCampaignForwardPaging response = check hsmCampaignsClient->/.get();
test:assertTrue(response?.results.length() > 0);
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
function testPostCreateMarketingCampaigns() returns error? {
PublicCampaign response = check baseClient->/.post(
PublicCampaign response = check hsmCampaignsClient->/.post(
payload = {
properties: {
"hs_name": "campaign" + time:utcNow().toString(),
Expand All @@ -69,18 +74,20 @@ function testPostCreateMarketingCampaigns() returns error? {
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testGetReadACampaign() returns error? {
PublicCampaignWithAssets response = check baseClient->/[campaignGuid];
PublicCampaignWithAssets response = check hsmCampaignsClient->/[campaignGuid];
test:assertEquals(response?.id, campaignGuid);
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPatchUpdateCampaigns() returns error? {
PublicCampaign response = check baseClient->/[campaignGuid].patch(
PublicCampaign response = check hsmCampaignsClient->/[campaignGuid].patch(
payload = {
properties: {
"hs_goal": "updatedCampaignGoal",
Expand All @@ -92,10 +99,11 @@ isolated function testPatchUpdateCampaigns() returns error? {
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPostBatchCreate() returns error? {
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check baseClient->/batch/create.post(
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check hsmCampaignsClient->/batch/create.post(
payload = {
"inputs": [
{
Expand All @@ -111,10 +119,11 @@ isolated function testPostBatchCreate() returns error? {
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPostBatchUpdate() returns error? {
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check baseClient->/batch/update.post(
BatchResponsePublicCampaign|BatchResponsePublicCampaignWithErrors response = check hsmCampaignsClient->/batch/update.post(
payload = {
"inputs": [
{
Expand All @@ -131,11 +140,12 @@ isolated function testPostBatchUpdate() returns error? {
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPostBatchRead() returns error? {
BatchResponsePublicCampaignWithAssets|BatchResponsePublicCampaignWithAssetsWithErrors response =
check baseClient->/batch/read.post(
check hsmCampaignsClient->/batch/read.post(
payload = {
"inputs": [
{
Expand All @@ -148,62 +158,69 @@ isolated function testPostBatchRead() returns error? {
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testGetReportsRevenue() returns error? {
RevenueAttributionAggregate response = check baseClient->/[campaignGuid]/reports/revenue;
RevenueAttributionAggregate response = check hsmCampaignsClient->/[campaignGuid]/reports/revenue;
test:assertTrue(response?.revenueAmount is decimal);
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testGetReportsMetrics() returns error? {
MetricsCounters response = check baseClient->/[campaignGuid]/reports/metrics;
MetricsCounters response = check hsmCampaignsClient->/[campaignGuid]/reports/metrics;
test:assertTrue(response?.sessions >= 0);
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testGetListAssets() returns error? {
CollectionResponsePublicCampaignAssetForwardPaging response = check baseClient->/[campaignGuid]/assets/[assetType];
CollectionResponsePublicCampaignAssetForwardPaging response = check hsmCampaignsClient->/[campaignGuid]/assets/[assetType];
test:assertTrue(response?.results.length() > 0);

}

@test:Config {
dependsOn: [testDeleteRemoveAssetAssociation],
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPutAddAssetAssociation() returns error? {
var response = check baseClient->/[campaignGuid]/assets/[assetType]/[assetID].put();
var response = check hsmCampaignsClient->/[campaignGuid]/assets/[assetType]/[assetID].put();
test:assertEquals(response.statusCode, 204);
}

@test:Config {
dependsOn: [testGetListAssets],
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testDeleteRemoveAssetAssociation() returns error? {
var response = check baseClient->/[campaignGuid]/assets/[assetType]/[assetID].delete();
var response = check hsmCampaignsClient->/[campaignGuid]/assets/[assetType]/[assetID].delete();
test:assertEquals(response.statusCode, 204);
}

@test:Config {
dependsOn: [testPostCreateMarketingCampaigns],
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
function testDeleteCampaign() returns error? {
var response = check baseClient->/[campaignGuid2].delete();
var response = check hsmCampaignsClient->/[campaignGuid2].delete();
test:assertEquals(response.statusCode, 204);
}

@test:Config {
groups: ["live_tests"]
groups: ["live_tests"],
enable: enableClient0auth2
}
isolated function testPostDeleteABatchOfCampaigns() returns error? {
var response = check baseClient->/batch/archive.post(
var response = check hsmCampaignsClient->/batch/archive.post(
payload = {
"inputs": [
{
Expand Down