-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ayeshLK/tests
Add smoke test cases for Stripe connector
- Loading branch information
Showing
8 changed files
with
1,818 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) 2024, 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; | ||
|
||
isolated string commonAccountId = ""; | ||
|
||
function setCommonAccountId(string accountId) { | ||
lock { | ||
commonAccountId = accountId; | ||
} | ||
} | ||
|
||
function getCommonAccountId() returns string { | ||
lock { | ||
return commonAccountId; | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"] | ||
} | ||
function createAccountTest() returns error? { | ||
accounts_body accountDetails = { | ||
country: "US", | ||
email: "jenny.rosen@example.com", | ||
default_currency: "usd" | ||
}; | ||
Account account = check stripe->/accounts.post(accountDetails); | ||
test:assertTrue(account.country is string, "Could not find the country setting"); | ||
test:assertTrue(account.default_currency is string, "Could not find the currency setting"); | ||
setCommonAccountId(account.id); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [createAccountTest] | ||
} | ||
function getAccountsTest() returns error? { | ||
AccountList accountsResponse = check stripe->/accounts; | ||
Account[] accounts = accountsResponse.data; | ||
test:assertTrue(accounts.length() > 0, "No accounts found"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [createAccountTest] | ||
} | ||
function getAccountTest() returns error? { | ||
string accountId = getCommonAccountId(); | ||
Account account = check stripe->/accounts/[accountId]; | ||
test:assertEquals(account.id, accountId, "Invalid account received"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"] | ||
} | ||
function deleteAccountTest() returns error? { | ||
accounts_body accountDetails = { | ||
country: "US", | ||
email: "jenny.rosen.deleted@example.com", | ||
default_currency: "usd" | ||
}; | ||
Account account = check stripe->/accounts.post(accountDetails); | ||
|
||
Deleted_account deletedAccount = check stripe->/accounts/[account.id].delete(); | ||
test:assertEquals(deletedAccount.id, account.id, "Invalid account deleted"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"] | ||
} | ||
function rejectAccountTest() returns error? { | ||
accounts_body accountDetails = { | ||
country: "US", | ||
email: "jenny.rosen.rejected@example.com", | ||
default_currency: "usd" | ||
}; | ||
Account account = check stripe->/accounts.post(accountDetails); | ||
|
||
account_reject_body accountReject = { | ||
reason: "fraud" | ||
}; | ||
Account rejectedAccount = check stripe->/accounts/[account.id]/reject.post(accountReject); | ||
test:assertEquals(rejectedAccount.id, account.id, "Invalid account rejected"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2024, 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; | ||
|
||
isolated string commonChargeId = ""; | ||
|
||
function setCommonChargeId(string chargeId) { | ||
lock { | ||
commonChargeId = chargeId; | ||
} | ||
} | ||
|
||
function getCommonChargeId() returns string { | ||
lock { | ||
return commonChargeId; | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"] | ||
} | ||
function createChargeTest() returns error? { | ||
charges_body chargeDetails = { | ||
amount: 100, | ||
currency: "usd", | ||
'source: "tok_visa" | ||
}; | ||
Charge charge = check stripe->/charges.post(chargeDetails); | ||
test:assertEquals(charge.amount, 100, "Invalid charge amount"); | ||
setCommonChargeId(charge.id); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [createChargeTest] | ||
} | ||
function getChargeTest() returns error? { | ||
string chargeId = getCommonChargeId(); | ||
Charge charge = check stripe->/charges/[chargeId]; | ||
test:assertEquals(charge.id, chargeId, "Invalid charge details found"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [createChargeTest] | ||
} | ||
function updateChargeTest() returns error? { | ||
string chargeId = getCommonChargeId(); | ||
record {|string...;|} metadata = { | ||
"shipping": "express" | ||
}; | ||
charges_charge_body chargeUpdate = { metadata }; | ||
Charge charge = check stripe->/charges/[chargeId].post(chargeUpdate); | ||
test:assertEquals(charge.metadata, metadata, "Invalid meta-data found"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [updateChargeTest] | ||
} | ||
function refundChargeTest() returns error? { | ||
string chargeId = getCommonChargeId(); | ||
charge_refund_body chargeRefund = { | ||
amount: 100 | ||
}; | ||
Charge charge = check stripe->/charges/[chargeId]/refund.post(chargeRefund); | ||
test:assertTrue(charge.refunded, "Charge refund was unsuccessful"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2024, 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; | ||
|
||
isolated string commonCustomerId = ""; | ||
|
||
function setCommonCustomerId(string customerId) { | ||
lock { | ||
commonCustomerId = customerId; | ||
} | ||
} | ||
|
||
function getCommonCustomerId() returns string { | ||
lock { | ||
return commonCustomerId; | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"] | ||
} | ||
function createCustomerTest() returns error? { | ||
customers_body newCustomer = { | ||
name: "John Doe", | ||
email: "john.doe@sample.com", | ||
address: { | ||
city: "Colombo", | ||
country: "Sri Lanka" | ||
} | ||
}; | ||
Customer customer = check stripe->/customers.post(newCustomer); | ||
test:assertEquals(customer?.name, "John Doe", "Invalid customer name"); | ||
setCommonCustomerId(customer.id); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [createCustomerTest] | ||
} | ||
function updateCustomerTest() returns error? { | ||
string customerId = getCommonCustomerId(); | ||
record {|string...;|} metadata = { | ||
"businessType": "Stock trading" | ||
}; | ||
customers_customer_body customerUpdate = { metadata }; | ||
Customer customer = check stripe->/customers/[customerId].post(customerUpdate); | ||
test:assertEquals(customer.metadata, metadata, "Invalid meta-data found"); | ||
} | ||
|
||
@test:Config { | ||
groups: ["live_tests", "mock_tests"], | ||
dependsOn: [updateCustomerTest] | ||
} | ||
function deleteCustomerTest() returns error? { | ||
string customerId = getCommonCustomerId(); | ||
Deleted_customer deletedCustomer = check stripe->/customers/[customerId].delete(); | ||
test:assertTrue(deletedCustomer.deleted, "Customer deletion successful"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2024, 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/log; | ||
import ballerina/os; | ||
|
||
configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; | ||
configurable string stripeSecret = isLiveServer ? os:getEnv("STRIPE_SECRET") : "test"; | ||
|
||
final Client stripe = check initClient(); | ||
|
||
function initClient() returns Client|error { | ||
if isLiveServer { | ||
log:printInfo("Running tests on actual server"); | ||
return new ({auth: {token: stripeSecret}}); | ||
} | ||
return new ({auth: {token: stripeSecret}}, "http://localhost:9090/v1"); | ||
} |
Oops, something went wrong.