Skip to content

Commit

Permalink
Merge pull request #4 from SenuDyl/main
Browse files Browse the repository at this point in the history
Create Mock Test Files, Update Live Tests
  • Loading branch information
MohamedSabthar authored Jan 17, 2025
2 parents 1b553ad + 4021b04 commit 966ba61
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 40 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ If you already have an account, go to the [HubSpot developer portal](https://app

If you don't have a HubSpot Developer Account, you can sign up to a free account [here](https://developers.hubspot.com/get-started).

### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account
### Step 2 (Optional): Create a Developer Test Account under your account

Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
Within app developer accounts, you can create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) to test apps and integrations without affecting any real HubSpot data.

>**Note:** These accounts are intended solely for development and testing purposes and should not be used in production environments.
Expand Down Expand Up @@ -158,7 +158,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
final hsmsubscriptions:ConnectionConfig hsmsubscriptionsConfig = {
final hsmsubscriptions:ConnectionConfig hsmSubscriptionsConfig = {
auth : {
clientId,
clientSecret,
Expand All @@ -167,7 +167,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
}
};
final hsmsubscriptions:Client hsmsubscriptions = check new (hsmsubscriptionsConfig);
final hsmsubscriptions:Client hsmSubscriptions = check new (hsmSubscriptionsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -178,7 +178,7 @@ Now, utilize the available connector operations. A sample use case is shown belo

```
public function main() returns error? {
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = getCommunicationPreferencesV4StatusesSubscriberidstring
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = check hsmSubscriptions->getCommunicationPreferencesV4StatusesSubscriberidstring
(subscriberUserId,channel = "EMAIL");
}
Expand Down
10 changes: 5 additions & 5 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ If you already have an account, go to the [HubSpot developer portal](https://app

If you don't have a HubSpot Developer Account, you can sign up to a free account [here](https://developers.hubspot.com/get-started).

### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account
### Step 2 (Optional): Create a Developer Test Account under your account

Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
Within app developer accounts, you can create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) to test apps and integrations without affecting any real HubSpot data.

>**Note:** These accounts are intended solely for development and testing purposes and should not be used in production environments.
Expand Down Expand Up @@ -150,7 +150,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
final hsmsubscriptions:ConnectionConfig hsmsubscriptionsConfig = {
final hsmsubscriptions:ConnectionConfig hsmSubscriptionsConfig = {
auth : {
clientId,
clientSecret,
Expand All @@ -159,7 +159,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
}
};
final hsmsubscriptions:Client hsmsubscriptions = check new (hsmsubscriptionsConfig);
final hsmsubscriptions:Client hsmSubscriptions = check new (hsmSubscriptionsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -170,7 +170,7 @@ Now, utilize the available connector operations. A sample use case is shown belo

```
public function main() returns error? {
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = getCommunicationPreferencesV4StatusesSubscriberidstring
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = check hsmSubscriptions->getCommunicationPreferencesV4StatusesSubscriberidstring
(subscriberUserId,channel = "EMAIL");
}
Expand Down
10 changes: 5 additions & 5 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ If you already have an account, go to the [HubSpot developer portal](https://app

If you don't have a HubSpot Developer Account, you can sign up to a free account [here](https://developers.hubspot.com/get-started).

### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account
### Step 2 (Optional): Create a Developer Test Account under your account

Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
Within app developer accounts, you can create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) to test apps and integrations without affecting any real HubSpot data.

>**Note:** These accounts are intended solely for development and testing purposes and should not be used in production environments.
Expand Down Expand Up @@ -150,7 +150,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
final hsmsubscriptions:ConnectionConfig hsmsubscriptionsConfig = {
final hsmsubscriptions:ConnectionConfig hsmSubscriptionsConfig = {
auth : {
clientId,
clientSecret,
Expand All @@ -159,7 +159,7 @@ import ballerinax/hubspot.marketing.subscriptions as hsmsubscriptions;
}
};
final hsmsubscriptions:Client hsmsubscriptions = check new (hsmsubscriptionsConfig);
final hsmsubscriptions:Client hsmSubscriptions = check new (hsmSubscriptionsConfig);
```

### Step 3: Invoke the connector operation
Expand All @@ -170,7 +170,7 @@ Now, utilize the available connector operations. A sample use case is shown belo

```
public function main() returns error? {
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = getCommunicationPreferencesV4StatusesSubscriberidstring
hsmsubscriptions: ActionResponseWithResultsPublicWideStatus response = check hsmSubscriptions->getCommunicationPreferencesV4StatusesSubscriberidstring
(subscriberUserId,channel = "EMAIL");
}
Expand Down
143 changes: 143 additions & 0 deletions ballerina/tests/mock_test.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/test;

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"
);

final string mockTestSubscriberUserId = "bh@hubspot.com";
final int:Signed32 mockTestSubscriptionId = 530858989;

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestGetCommunicationPreferencesbySubscriberId() returns error? {
ActionResponseWithResultsPublicStatus response = check hubspot
->getCommunicationPreferencesV4StatusesSubscriberidstring
(testSubscriberUserId, channel = "EMAIL");
test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");

}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestPostCommunicationPreferencesbySubscriberId() returns error? {
ActionResponseWithResultsPublicStatus response = check hubspot
->postCommunicationPreferencesV4StatusesSubscriberidstring
(testSubscriberUserId,
payload = {
channel: "EMAIL",
statusState: "SUBSCRIBED",
subscriptionId: testSubscriptionId

}
);

test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestGetUnsubscribedStatusbySubscriberId() returns error? {
ActionResponseWithResultsPublicWideStatus response = check hubspot
->getCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll(testSubscriberUserId, channel = "EMAIL");

test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestPostBatchUnsubscribeAll() returns error? {
BatchInputString payload = {
inputs: [testSubscriberUserId]
};
BatchResponsePublicWideStatusBulkResponse response = check hubspot
->postCommunicationPreferencesV4StatusesBatchUnsubscribeAllRead
(payload, channel = "EMAIL");

test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestPostCommunicationPreferencesBatchRead() returns error? {
BatchInputString payload = {
inputs: [testSubscriberUserId]
};

BatchResponsePublicStatusBulkResponse response = check hubspot
->postCommunicationPreferencesV4StatusesBatchRead
(payload, channel = "EMAIL");

test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestPostCommunicationPreferencesBatchWrite() returns error? {
PublicStatusRequest request = {
statusState: "SUBSCRIBED",
channel: "EMAIL",
subscriberIdString: testSubscriberUserId,
subscriptionId: testSubscriptionId
};
BatchInputPublicStatusRequest payload = {
inputs: [request]
};

BatchResponsePublicStatus response = check hubspot
->postCommunicationPreferencesV4StatusesBatchWrite(payload);

test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestPostUnsubscribeAllbySubscriberId() returns error? {
ActionResponseWithResultsPublicStatus response = check hubspot
->postCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll(testSubscriberUserId, channel = "EMAIL");
test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

@test:Config {
groups: ["mock_tests"]
}

isolated function mockTestGetSubscriptionStatusDefinitions() returns error? {
ActionResponseWithResultsSubscriptionDefinition response = check hubspot
->getCommunicationPreferencesV4Definitions();
test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");
}

31 changes: 19 additions & 12 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ configurable string refreshToken = ?;
final string serviceUrl = isLiveServer ? "https://api.hubapi.com/communication-preferences/v4" : "http://localhost:9090";

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

Expand All @@ -36,19 +36,20 @@ final string testSubscriberUserId = "bh@hubspot.com";
final int:Signed32 testSubscriptionId = 530858989;

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testGetCommunicationPreferencesbySubscriberId() returns error? {
ActionResponseWithResultsPublicStatus response = check hubspot
->getCommunicationPreferencesV4StatusesSubscriberidstring
(testSubscriberUserId, channel = "EMAIL");
test:assertEquals(response.status, "COMPLETE", "Status should be 'COMPLETE'.");

}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testPostCommunicationPreferencesbySubscriberId() returns error? {
Expand All @@ -66,7 +67,8 @@ isolated function testPostCommunicationPreferencesbySubscriberId() returns error
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testGetUnsubscribedStatusbySubscriberId() returns error? {
Expand All @@ -76,7 +78,8 @@ isolated function testGetUnsubscribedStatusbySubscriberId() returns error? {
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testPostBatchUnsubscribeAll() returns error? {
Expand All @@ -90,7 +93,8 @@ isolated function testPostBatchUnsubscribeAll() returns error? {
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testPostCommunicationPreferencesBatchRead() returns error? {
Expand All @@ -105,7 +109,8 @@ isolated function testPostCommunicationPreferencesBatchRead() returns error? {
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testPostCommunicationPreferencesBatchWrite() returns error? {
Expand All @@ -125,7 +130,8 @@ isolated function testPostCommunicationPreferencesBatchWrite() returns error? {
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testPostUnsubscribeAllbySubscriberId() returns error? {
Expand All @@ -135,7 +141,8 @@ isolated function testPostUnsubscribeAllbySubscriberId() returns error? {
}

@test:Config {
groups: ["live_tests", "mock_tests"]
enable: isLiveServer,
groups: ["live_tests"]
}

isolated function testGetSubscriptionStatusDefinitions() returns error? {
Expand Down
Loading

0 comments on commit 966ba61

Please sign in to comment.