Skip to content

Commit

Permalink
seperated mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ParameswaranSajeenthiran committed Jan 10, 2025
1 parent 8d89546 commit 82f73a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 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
46 changes: 33 additions & 13 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import ballerina/http;
import ballerina/test;

configurable boolean isLiveServer =?;
configurable boolean isLiveServer =false;
configurable boolean isOauth = ?;
configurable string oauthKey = ?;
configurable string apiKey = ?;
Expand All @@ -32,8 +32,11 @@ ConnectionConfig apikeyConfig = {
}
};

string serviceUrl = isLiveServer ? "https://api.hubapi.com/automation/v4/actions" : "http://localhost:8080/mock";


// Client initialization
final Client hubspotAutomation = check new Client(apikeyConfig, "https://api.hubapi.com/automation/v4/actions");
final Client hubspotAutomation = check new Client(apikeyConfig, serviceUrl);

// Sample Extension Definition
string createdExtensionId = "";
Expand Down Expand Up @@ -87,7 +90,9 @@ PublicActionDefinitionEgg testingPublicActionDefinitionEgg = {
#
# + return - error? if an error occurs, null otherwise
#
@test:Config {groups: ["apikey"]}
@test:Config {
groups: ["apikey"],
enable: isLiveServer}
function testPost() returns error? {
PublicActionDefinition response = check hubspotAutomation->/[appId].post(testingPublicActionDefinitionEgg);

Expand All @@ -103,7 +108,8 @@ function testPost() returns error? {
#
@test:Config {
groups: ["apikey"],
dependsOn: [testPost]
dependsOn: [testPost],
enable: isLiveServer
}
function testPostFunction() returns error? {
PublicActionFunctionIdentifier response = check hubspotAutomation->/[appId]/[createdExtensionId]/functions/["POST_FETCH_OPTIONS"].put("exports.main = (event, callback) => {\r\n callback({\r\n \"options\": [{\r\n \"label\": \"Big Widget\",\r\n \"description\": \"Big Widget\",\r\n \"value\": \"10\"\r\n },\r\n {\r\n \"label\": \"Small Widget\",\r\n \"description\": \"Small Widget\",\r\n \"value\": \"1\"\r\n }\r\n ]\r\n });\r\n}");
Expand All @@ -114,7 +120,8 @@ function testPostFunction() returns error? {

@test:Config {
dependsOn: [testPost],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer
}
function testGetDefinitionById() returns error? {
PublicActionDefinition response = check hubspotAutomation->/[appId]/[createdExtensionId];
Expand Down Expand Up @@ -145,7 +152,9 @@ function testGetDefinitionById() returns error? {

@test:Config {
dependsOn: [testPostFunction],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer

}
function testGetAllFunctions() returns error? {
CollectionResponsePublicActionFunctionIdentifierNoPaging response = check hubspotAutomation->/[appId]/[createdExtensionId]/functions;
Expand All @@ -159,7 +168,9 @@ function testGetAllFunctions() returns error? {
#
# + return - error? if an error occurs, null otherwise
#
@test:Config {groups: ["apikey"]}
@test:Config {groups: ["apikey"],
enable: isLiveServer
}
function testGetPagedExtensionDefinitions() returns error? {
CollectionResponsePublicActionDefinitionForwardPaging response = check hubspotAutomation->/[appId];

Expand All @@ -173,7 +184,9 @@ function testGetPagedExtensionDefinitions() returns error? {
#
@test:Config {
dependsOn: [testPost],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer

}
function testGetAllRevisions() returns error? {
CollectionResponsePublicActionRevisionForwardPaging response = check hubspotAutomation->/[appId]/[createdExtensionId]/revisions;
Expand All @@ -188,7 +201,9 @@ function testGetAllRevisions() returns error? {
#
@test:Config {
dependsOn: [testPost],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer

}
function testGetRevision() returns error? {
PublicActionRevision response = check hubspotAutomation->/[appId]/[createdExtensionId]/revisions/["1"];
Expand All @@ -210,7 +225,9 @@ function testGetRevision() returns error? {
#
@test:Config {
dependsOn: [testPost, testDeleteFunction],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer

}
function testDelete() returns error? {

Expand All @@ -227,7 +244,9 @@ function testDelete() returns error? {
#
@test:Config {
dependsOn: [testPost],
groups: ["apikey"]
groups: ["apikey"],
enable: isLiveServer

}
function testDeleteFunction() returns error? {
PublicActionFunction response = check hubspotAutomation->/[appId]/[createdExtensionId]/functions/["POST_ACTION_EXECUTION"];
Expand All @@ -242,7 +261,9 @@ function testDeleteFunction() returns error? {
# + return - error? if an error occurs, null otherwise
#
@test:Config {
groups: ["oauth"]
groups: ["oauth"],
enable: !isLiveServer

}
function testRespondBatch() returns error? {

Expand All @@ -252,7 +273,6 @@ function testRespondBatch() returns error? {
token: oauthKey
}
};
string serviceUrl = isLiveServer ? "https://api.hubapi.com/automation/v4/actions" : "http://localhost:8080/mock";

final Client hubspotAutomationOauth = check new Client(oauthConfig, serviceUrl);

Expand Down

0 comments on commit 82f73a2

Please sign in to comment.