Skip to content

Commit

Permalink
Merge pull request #4 from Pasindu599/main
Browse files Browse the repository at this point in the history
Fix Live Test, Create Mock Test Files.
  • Loading branch information
ThisaruGuruge authored Jan 17, 2025
2 parents 8c317df + 3496e7b commit 2be1c30
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[HubSpot ](https://www.hubspot.com/) is an AI-powered customer relationship management (CRM) platform.

The "hubspot.marketing.forms" offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).
The `hubspot.marketing.forms` offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).

> **Note:** This package may be changed in the future based on the HubSpot API changes, since it is currently under development and is subject to change based on testing and feedback. By using this package, you are agreeing to accept any future changes that might occur and understand the risk associated with testing an unstable API.
> Refer to the [HubSpot Developer Terms](https://legal.hubspot.com/developer-terms) & [Developer Beta Terms](https://legal.hubspot.com/developerbetaterms) for more information.
Expand Down
4 changes: 4 additions & 0 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[HubSpot](https://www.hubspot.com/) is an AI-powered customer relationship management (CRM) platform.

The "hubspot.marketing.forms" offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).
The `hubspot.marketing.forms` offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).

> **Note:** This package may be changed in the future based on the HubSpot API changes, since it is currently under development and is subject to change based on testing and feedback. By using this package, you are agreeing to accept any future changes that might occur and understand the risk associated with testing an unstable API.
> Refer to the [HubSpot Developer Terms](https://legal.hubspot.com/developer-terms) & [Developer Beta Terms](https://legal.hubspot.com/developerbetaterms) for more information.
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[HubSpot ](https://www.hubspot.com/) is an AI-powered customer relationship management (CRM) platform.

The "hubspot.marketing.forms" offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).
The `hubspot.marketing.forms` offers APIs to connect and interact with the [Marketing Forms](https://developers.hubspot.com/docs/reference/api/marketing/forms) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).

> **Note:** This package may be changed in the future based on the HubSpot API changes, since it is currently under development and is subject to change based on testing and feedback. By using this package, you are agreeing to accept any future changes that might occur and understand the risk associated with testing an unstable API.
> Refer to the [HubSpot Developer Terms](https://legal.hubspot.com/developer-terms) & [Developer Beta Terms](https://legal.hubspot.com/developerbetaterms) for more information.
Expand Down
18 changes: 15 additions & 3 deletions ballerina/tests/mock_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@

import ballerina/test;

final Client mockClient = check new (config, serviceUrl = "http://localhost:9090/marketing/v3/forms");
// create mock client
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/forms"
);

final string mockFormId = "b6336282-50ec-465e-894e-e368146fa25f";

@test:Config {}
@test:Config {
groups: ["mock_service_test"]
}
isolated function mockTestGetForm() returns error? {
CollectionResponseFormDefinitionBaseForwardPaging response = check mockClient->/.get();
test:assertTrue(response?.results.length() > 0);
}

@test:Config {}
@test:Config {
groups: ["mock_service_test"]
}
isolated function mockTestGetFormById() returns error? {
FormDefinitionBase response = check mockClient->/[mockFormId].get();
test:assertEquals(response?.id, mockFormId);
Expand Down
32 changes: 21 additions & 11 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,40 @@
// 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";

OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER // this line should be added to create auth object.
credentialBearer: oauth2:POST_BODY_BEARER

};

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

final time:Utc currentUtc = time:utcNow();
string formId = "";

@test:Config {}
@test:Config {
groups: ["live_service_test"]
}
isolated function testGetForm() returns error? {
CollectionResponseFormDefinitionBaseForwardPaging response = check baseClient->/.get();
test:assertTrue(response?.results.length() > 0);
}

@test:Config {}
@test:Config {
groups: ["live_service_test"]
}
function testCreateForm() returns error? {
FormDefinitionBase response = check baseClient->/.post(
{
Expand Down Expand Up @@ -121,7 +127,8 @@ function testCreateForm() returns error? {
}

@test:Config {
dependsOn: [testCreateForm]
dependsOn: [testCreateForm],
groups: ["live_service_test"]
}
function testGetFormById() returns error? {
FormDefinitionBase response = check baseClient->/[formId]();
Expand All @@ -130,7 +137,8 @@ function testGetFormById() returns error? {
}

@test:Config {
dependsOn: [testCreateForm]
dependsOn: [testCreateForm],
groups: ["live_service_test"]
}
function testUpdateEntireForm() returns error? {
FormDefinitionBase response = check baseClient->/[formId].put(
Expand Down Expand Up @@ -210,7 +218,8 @@ function testUpdateEntireForm() returns error? {
}

@test:Config {
dependsOn: [testCreateForm]
dependsOn: [testCreateForm],
groups: ["live_service_test"]
}
function testUpdateForm() returns error? {
FormDefinitionBase response = check baseClient->/[formId].patch(
Expand All @@ -222,7 +231,8 @@ function testUpdateForm() returns error? {
}

@test:Config {
dependsOn: [testCreateForm]
dependsOn: [testCreateForm],
groups: ["live_service_test"]
}
function testDeleteForm() returns error? {
json response = check baseClient->/[formId].delete();
Expand Down
2 changes: 1 addition & 1 deletion examples/contact-us-form/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ version = "0.1.0"
distribution = "2201.10.3"

[build-options]
observabilityIncluded = true
observabilityIncluded = true
18 changes: 8 additions & 10 deletions examples/contact-us-form/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ forms:OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER // this line should be added in to when you are going to create auth object.
credentialBearer: oauth2:POST_BODY_BEARER
};
final forms:Client baseClient = check new ({auth});
final forms:Client formsClient = check new ({auth});
public function main() returns error? {
forms:FormDefinitionCreateRequestBase inputFormDefinition = {
formType: "hubspot",
name: "Contact Us Form",
name: "Contact Us Form New",
createdAt: "2024-12-23T07:13:28.102Z",
updatedAt: "2024-12-23T07:13:28.102Z",
archived: false,
Expand Down Expand Up @@ -97,12 +97,12 @@ public function main() returns error? {
'type: "none"
}
};
forms:FormDefinitionBase response = check baseClient->/.post(
forms:FormDefinitionBase response = check formsClient->/.post(
inputFormDefinition
);
string formId = response?.id;
io:println("Form is created with ID: " + formId);
forms:FormDefinitionBase updateResponse = check baseClient->/[formId].patch(
forms:FormDefinitionBase updateResponse = check formsClient->/[formId].patch(
{
fieldGroups: [
{
Expand Down Expand Up @@ -182,10 +182,8 @@ public function main() returns error? {
}
);
io:println("Form is updated at" + updateResponse?.updatedAt);
forms:FormDefinitionBase getResponse = check baseClient->/[formId]();
forms:FormDefinitionBase getResponse = check formsClient->/[formId]();
io:println("Form is created at" + getResponse?.createdAt);
json deleteResponse = check baseClient->/[formId].delete();
if (deleteResponse == null) {
io:println("Form is deleted");
}
json deleteResponse = check formsClient->/[formId].delete();
io:println(formId+ "Form is deleted at" + deleteResponse.toString());
};
1 change: 1 addition & 0 deletions examples/sign-up-form/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ distribution = "2201.10.3"

[build-options]
observabilityIncluded = true

16 changes: 7 additions & 9 deletions examples/sign-up-form/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ forms:OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER // this line should be added in to when you are going to create auth object.
credentialBearer: oauth2:POST_BODY_BEARER
};
final forms:Client baseClient = check new ({auth});
final forms:Client formsClient = check new ({auth});
public function main() returns error? {
forms:FormDefinitionCreateRequestBase inputFormDefinition = {
formType: "hubspot",
Expand Down Expand Up @@ -98,12 +98,12 @@ public function main() returns error? {
}
};

forms:FormDefinitionBase response = check baseClient->/.post(
forms:FormDefinitionBase response = check formsClient->/.post(
inputFormDefinition
);
string formId = response?.id;
io:println("Form is created with ID: " + formId);
forms:FormDefinitionBase updateResponse = check baseClient->/[formId].patch(
forms:FormDefinitionBase updateResponse = check formsClient->/[formId].patch(
{
fieldGroups: [
{
Expand Down Expand Up @@ -183,10 +183,8 @@ public function main() returns error? {
}
);
io:println("Form is updated at" + updateResponse?.updatedAt);
forms:FormDefinitionBase getResponse = check baseClient->/[formId]();
forms:FormDefinitionBase getResponse = check formsClient->/[formId]();
io:println("Form is created at" + getResponse?.createdAt);
json deleteResponse = check baseClient->/[formId].delete();
if (deleteResponse == null) {
io:println("Form is deleted");
}
json deleteResponse = check formsClient->/[formId].delete();
io:println(formId+ "Form is deleted at" + deleteResponse.toString());
};

0 comments on commit 2be1c30

Please sign in to comment.