diff --git a/.travis.yml b/.travis.yml index 0a56809..a3641bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,14 +5,14 @@ node_js: - '6.15.1' #boron - '8.14.0' #carbon - '10.14.2' #dubnium -- stable +- '14.15.0' #stable script: - npm run prepublish-prod after_success: -- if [ $TRAVIS_NODE_VERSION = 'stable' ] && [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ]; then sh ./scripts/travisPublishDocs.sh; fi -- if [ $TRAVIS_NODE_VERSION = 'stable' ]; then npm run coveralls; fi +- if [ $TRAVIS_NODE_VERSION = '14.15.0' ] && [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ]; then sh ./scripts/travisPublishDocs.sh; fi +- if [ $TRAVIS_NODE_VERSION = '14.15.0' ]; then npm run coveralls; fi env: global: diff --git a/CHANGELOG.md b/CHANGELOG.md index 13d7066..c24c681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ Changelog ========= + +2.0.0 +------------------- +- Accesses V4 Rest APIs +- Added Business Stakeholders +- Added updatePaypalAccount, getPayPalAccountStatusTransition, listPayPalAccountStatusTransitions +- Added listTransferMethods +- Added getTransferStatusTransition, listTransferStatusTransition +- Added filters + 1.5.0 ------------------- - Added Venmo accounts diff --git a/README.md b/README.md index 7845da8..c187b77 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Hyperwallet REST SDK (Beta) =========================== -A library to manage users, transfer methods and payments through the Hyperwallet Rest V3 API +A library to manage users, transfer methods and payments through the Hyperwallet Rest V4 API +To access Rest V3 APIs please use SDK v1.5 Prerequisites ------------ diff --git a/src/Hyperwallet.js b/src/Hyperwallet.js index 3afb9f2..4228e74 100644 --- a/src/Hyperwallet.js +++ b/src/Hyperwallet.js @@ -19,7 +19,6 @@ export default class Hyperwallet { if (!username || !password) { throw new Error("You need to specify your API username and password!"); } - /** * The instance of the ApiClient * @@ -91,6 +90,10 @@ export default class Hyperwallet { * @param {api-callback} callback - The callback for this call */ listUsers(options, callback) { + const LIST_USER_FILTERS = ["clientUserId", "email", "programToken", "status", "verificationStatus"]; + if (options && !this.isValidFilter(options, LIST_USER_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_FILTERS)); + } this.client.doGet("users", options, Hyperwallet.handle204Response(callback)); } @@ -229,6 +232,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_USER_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_USER_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -322,6 +329,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_PREPAID_CARDS_FILTERS = ["status"]; + if (options && !this.isValidFilter(options, LIST_PREPAID_CARDS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARDS_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/prepaid-cards`, options, Hyperwallet.handle204Response(callback)); } @@ -516,6 +527,10 @@ export default class Hyperwallet { if (!prepaidCardToken) { throw new Error("prepaidCardToken is required"); } + const LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PREPAID_CARD_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/prepaid-cards/${encodeURIComponent(prepaidCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -590,6 +605,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_BANK_CARDS_FILTERS = ["status"]; + if (options && !this.isValidFilter(options, LIST_BANK_CARDS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARDS_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards`, options, Hyperwallet.handle204Response(callback)); } @@ -674,6 +693,10 @@ export default class Hyperwallet { if (!bankCardToken) { throw new Error("bankCardToken is required"); } + const LIST_BANK_CARD_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_BANK_CARD_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_CARD_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards/${encodeURIComponent(bankCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -767,6 +790,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_PAPER_CHECKS_FILTERS = ["status"]; + if (options && !this.isValidFilter(options, LIST_PAPER_CHECKS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECKS_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/paper-checks`, options, Hyperwallet.handle204Response(callback)); } @@ -851,6 +878,10 @@ export default class Hyperwallet { if (!paperCheckToken) { throw new Error("paperCheckToken is required"); } + const LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PAPER_CHECK_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/paper-checks/${encodeURIComponent(paperCheckToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -899,6 +930,10 @@ export default class Hyperwallet { * @param {api-callback} callback - The callback for this call */ listTransfers(options, callback) { + const LIST_TRANSFERS_FILTERS = ["clientTransferId", "sourceToken", "destinationToken"]; + if (options && !this.isValidFilter(options, LIST_TRANSFERS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_TRANSFERS_FILTERS)); + } this.client.doGet("transfers", options, Hyperwallet.handle204Response(callback)); } @@ -1032,9 +1067,79 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_PAYPAL_ACCOUNTS_FILTERS = ["status"]; + if (options && !this.isValidFilter(options, LIST_PAYPAL_ACCOUNTS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYPAL_ACCOUNTS_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts`, options, Hyperwallet.handle204Response(callback)); } + /** + * Update a PayPal account + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - The PayPal account token + * @param {Object} data - The PayPal account data to update + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken or payPalAccountToken is not provided + */ + updatePayPalAccount(userToken, payPalAccountToken, data, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + this.client.doPut(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}`, data, {}, callback); + } + + /** + * Activate a PayPal account + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - The PayPal account token + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken or payPalAccountToken is not provided + */ + activatePayPalAccount(userToken, payPalAccountToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + + const transition = { + transition: "ACTIVATED", + }; + this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, transition, {}, callback); + } + + /** + * Deactivate a PayPal account + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - The PayPal account token + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken or payPalAccountToken is not provided + */ + deactivatePayPalAccount(userToken, payPalAccountToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + + const transition = { + transition: "DE_ACTIVATED", + }; + this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, transition, {}, callback); + } + /** * Create PayPal account status transition * @@ -1055,6 +1160,48 @@ export default class Hyperwallet { this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, data, {}, callback); } + /** + * Get PayPal account status transition + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - PayPal account token + * @param {string} statusTransitionToken - The PayPal account status transition token + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken or payPalAccountToken or statusTransitionToken is not provided + */ + getPayPalAccountStatusTransition(userToken, payPalAccountToken, statusTransitionToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + if (!statusTransitionToken) { + throw new Error("statusTransitionToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions/${encodeURIComponent(statusTransitionToken)}`, + {}, callback); + } + + /** + * List PayPal account status transition + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - PayPal account token + * @param {Object} options - The query parameters to send + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken or payPalAccountToken is not provided + */ + listPayPalAccountStatusTransitions(userToken, payPalAccountToken, options, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); + } + //-------------------------------------- // Bank Accounts //-------------------------------------- @@ -1126,6 +1273,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_BANK_ACCOUNTS_FILTERS = ["type", "status"]; + if (options && !this.isValidFilter(options, LIST_BANK_ACCOUNTS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_ACCOUNTS_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-accounts`, options, Hyperwallet.handle204Response(callback)); } @@ -1145,7 +1296,6 @@ export default class Hyperwallet { if (!bankAccountToken) { throw new Error("bankAccountToken is required"); } - const transition = { transition: "DE-ACTIVATED", }; @@ -1215,6 +1365,10 @@ export default class Hyperwallet { if (!bankAccountToken) { throw new Error("bankAccountToken is required"); } + const LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_BANK_ACCOUNT_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-accounts/${encodeURIComponent(bankAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -1235,6 +1389,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_USER_BALANCE_FILTERS = ["currency"]; + if (options && !this.isValidFilter(options, LIST_USER_BALANCE_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_USER_BALANCE_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/balances`, options, Hyperwallet.handle204Response(callback)); } @@ -1255,6 +1413,7 @@ export default class Hyperwallet { if (!prepaidCardToken) { throw new Error("prepaidCardToken is required"); } + this.client.doGet(`users/${encodeURIComponent(userToken)}/prepaid-cards/${encodeURIComponent(prepaidCardToken)}/balances`, options, Hyperwallet.handle204Response(callback)); } @@ -1308,13 +1467,19 @@ export default class Hyperwallet { this.client.doGet(`payments/${encodeURIComponent(paymentToken)}`, {}, callback); } + /** * List all payments * * @param {Object} options - The query parameters to send * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if invalid payment is provided */ listPayments(options, callback) { + const LIST_PAYMENT_FILTERS = ["clientPaymentId"]; + if (options && !this.isValidFilter(options, LIST_PAYMENT_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYMENT_FILTERS)); + } this.client.doGet("payments", options, Hyperwallet.handle204Response(callback)); } @@ -1368,6 +1533,11 @@ export default class Hyperwallet { if (!paymentToken) { throw new Error("paymentToken is required"); } + const LIST_PAYMENT_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_PAYMENT_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_PAYMENT_STATUS_TRANSITION_FILTERS)); + } + this.client.doGet(`payments/${encodeURIComponent(paymentToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } @@ -1468,6 +1638,10 @@ export default class Hyperwallet { if (!userToken) { throw new Error("userToken is required"); } + const LIST_TRANSFER_METHOD_CONFIG_FILTERS = ["userToken"]; + if (options && !this.isValidFilter(options, LIST_TRANSFER_METHOD_CONFIG_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_TRANSFER_METHOD_CONFIG_FILTERS)); + } const params = options ? objectAssign({}, options, { userToken }) : { userToken }; this.client.doGet("transfer-method-configurations", params, Hyperwallet.handle204Response(callback)); } @@ -1567,6 +1741,10 @@ export default class Hyperwallet { * @param {api-callback} callback - The callback for this call */ listWebhookNotifications(options, callback) { + const LIST_WEBHOOK_NOTIFICATIONS_FILTERS = ["programToken", "type"]; + if (options && !this.isValidFilter(options, LIST_WEBHOOK_NOTIFICATIONS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_WEBHOOK_NOTIFICATIONS_FILTERS)); + } this.client.doGet("webhook-notifications", options, Hyperwallet.handle204Response(callback)); } @@ -1621,7 +1799,9 @@ export default class Hyperwallet { return (err, data, res) => { if (!err && res.status === 204) { callback(err, { - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }, res); return; @@ -1797,6 +1977,259 @@ export default class Hyperwallet { if (!venmoAccountToken) { throw new Error("venmoAccountToken is required"); } + const LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS = ["transition"]; + if (options && !this.isValidFilter(options, LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_VENMO_ACCOUNT_STATUS_TRANSITION_FILTERS)); + } this.client.doGet(`users/${encodeURIComponent(userToken)}/venmo-accounts/${encodeURIComponent(venmoAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } + + /** + * Validate the options filter + * + * @param {Object} inputFilters - The query parameters in the URI + * @param {Object} listFilters - Defined list of filters for a business object + */ + + isValidFilter(inputFilters, listFilters) { + return Object.keys(inputFilters).every(elem => listFilters.includes(elem)); + } + + //-------------------------------------- + // Business StakeHolder + //-------------------------------------- + + /** + * Create a Business Stakeholder + * + * @param {string} userToken - The Stakeholder token + * @param {Object} data - The Stakeholder data + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken is not provided + */ + createBusinessStakeholder(userToken, data, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + this.client.doPost(`users/${encodeURIComponent(userToken)}/business-stakeholders`, data, {}, callback); + } + + /** + * Update a Business Stakeholder + * + * @param {string} userToken - The user token + * @param {string} stakeholderToken - The user token + * @param {Object} data - The Stakeholder data that should be updated + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken is not provided + */ + updateBusinessStakeholder(userToken, stakeholderToken, data, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + this.client.doPut(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}`, data, {}, callback); + } + + /** + * List all Business Stakeholder + * + * @param {string} userToken - The user token + * @param {Object} options - The query parameters to send + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken is not provided + */ + listBusinessStakeholders(userToken, options, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + const LIST_BUSINESS_STAKEHOLDERS_FILTERS = ["status", "isBusinessContact", "isDirector", "isUltimateBeneficialOwner"]; + if (options && !this.isValidFilter(options, LIST_BUSINESS_STAKEHOLDERS_FILTERS)) { + throw new Error("Invalid Filter. Expected - ".concat(LIST_BUSINESS_STAKEHOLDERS_FILTERS)); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/business-stakeholders`, options, Hyperwallet.handle204Response(callback)); + } + + /** + * Activate a Business Stakeholder transition + * + * @param {string} userToken - user token + * @param {string} stakeholderToken - stakeholder token + * @param {api-callback} callback - callback for this call + * @throws Will throw an error if userToken is not provided + */ + activateBusinessStakeholder(userToken, stakeholderToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + const data = { + transition: "ACTIVATED", + }; + this.createBusinessStakeholderStatusTransition(userToken, stakeholderToken, data, callback); + } + + /** + * Deactivate a Business Stakeholder transition + * + * @param {string} userToken - user token + * @param {string} stakeholderToken - stakeholder token + * @param {api-callback} callback - callback for this call + * @throws Will throw an error if userToken is not provided + */ + deactivateBusinessStakeholder(userToken, stakeholderToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + const data = { + transition: "DE_ACTIVATED", + }; + this.createBusinessStakeholderStatusTransition(userToken, stakeholderToken, data, callback); + } + + /** + * Create a Business Stakeholder transition + * + * @param {string} userToken - user token + * @param {string} stakeholderToken - stakeholder token + * @param {Object} data - Stakeholder transition data + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken is not provided + */ + createBusinessStakeholderStatusTransition(userToken, stakeholderToken, data, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + this.client.doPost(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}/status-transitions`, data, {}, callback); + } + + /** + * Get Business Stakeholder status transition + * + * @param {string} userToken -user token + * @param {string} stakeholderToken - The Business Stakeholder token + * @param {string} statusTransitionToken - The Business Stakeholder status transition token + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken or stakeholderToken is not provided + */ + getBusinessStakeholderStatusTransition(userToken, stakeholderToken, statusTransitionToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + if (!statusTransitionToken) { + throw new Error("statusTransitionToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}/status-transitions/${encodeURIComponent(statusTransitionToken)}`, + {}, + callback); + } + + /** + * List all Business Stakeholder status transitions + * + * @param {string} userToken - user token + * @param {string} stakeholderToken - Business Stakeholder token + * @param {Object} options - query parameters to send + * @param {api-callback} callback - callback for this call + * + * @throws Will throw an error if userToken or stakeholderToken is not provided + */ + listBusinessStakeholderStatusTransitions(userToken, stakeholderToken, options, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); + } + + /** + * Upload Documents to Business Stakeholder + * + * @param {string} userToken - The user token + * @param {string} stakeholderToken - stakeholder token + * @param {Object} data - JSON object of the data and files to be uploaded + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken is not provided + */ + uploadBusinessStakeholderDocuments(userToken, stakeholderToken, data, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!stakeholderToken) { + throw new Error("stakeholderToken is required"); + } + if (!data) { + throw new Error("Files for upload are required"); + } + this.client.doPutMultipart(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}`, data, callback); + } + + /** + * List of Transfer Methods + * + * @param {string} userToken - The user token + * @param {Object} options - The query parameters to send + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken is not provided + */ + listTransferMethods(userToken, options, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/transfer-methods`, options, Hyperwallet.handle204Response(callback)); + } + + /** + * Get a transfer status transition + * + * @param {string} transferToken - The transfer token + * @param {string} statusTransitionToken - The status transition token token + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if transferToken is not provided + * @throws Will throw an error if statusTransitionToken is not provided + */ + getTransferStatusTransition(transferToken, statusTransitionToken, callback) { + if (!transferToken) { + throw new Error("transferToken is required"); + } + if (!statusTransitionToken) { + throw new Error("statusTransitionToken is required"); + } + this.client.doGet(`transfers/${encodeURIComponent(transferToken)}/status-transitions/${encodeURIComponent(statusTransitionToken)}`, {}, callback); + } + + /** + * List all transfer status transitions + * + * @param {string} transferToken - The transfer token + * @param {Object} options - The query parameters to send + * @param {api-callback} callback - The callback for this call + */ + listTransferStatusTransition(transferToken, options, callback) { + if (!transferToken) { + throw new Error("transferToken is required"); + } + this.client.doGet(`transfers/${encodeURIComponent(transferToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); + } } diff --git a/src/utils/ApiClient.js b/src/utils/ApiClient.js index 93a86df..bfa19d8 100644 --- a/src/utils/ApiClient.js +++ b/src/utils/ApiClient.js @@ -77,7 +77,7 @@ export default class ApiClient { /** * Do a POST call to the Hyperwallet API server * - * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v3/`) + * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v4/`) * @param {Object} data - The data to send to the server * @param {Object} params - Query parameters to send in this call * @param {api-callback} callback - The callback for this call @@ -94,7 +94,7 @@ export default class ApiClient { } requestDataPromise.then((requestData) => { request - .post(`${this.server}/rest/v3/${partialUrl}`) + .post(`${this.server}/rest/v4/${partialUrl}`) .auth(this.username, this.password) .set("User-Agent", `Hyperwallet Node SDK v${this.version}`) .type(contentType) @@ -108,7 +108,7 @@ export default class ApiClient { /** * Do a PUT call to the Hyperwallet API server to upload documents * - * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v3/`) + * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v4/`) * @param {Object} data - The data to send to the server * @param {api-callback} callback - The callback for this call */ @@ -128,7 +128,7 @@ export default class ApiClient { } requestDataPromise.then(() => { const req = request - .put(`${this.server}/rest/v3/${partialUrl}`) + .put(`${this.server}/rest/v4/${partialUrl}`) .auth(this.username, this.password) .set("User-Agent", `Hyperwallet Node SDK v${this.version}`) .type(contentType) @@ -147,7 +147,7 @@ export default class ApiClient { /** * Do a PUT call to the Hyperwallet API server * - * @param {string} partialUrl - The api endpoint to call (gets prefixed by server and /rest/v3/) + * @param {string} partialUrl - The api endpoint to call (gets prefixed by server and /rest/v4/) * @param {Object} data - The data to send to the server * @param {Object} params - Query parameters to send in this call * @param {api-callback} callback - The callback for this call @@ -164,7 +164,7 @@ export default class ApiClient { } requestDataPromise.then((requestData) => { request - .put(`${this.server}/rest/v3/${partialUrl}`) + .put(`${this.server}/rest/v4/${partialUrl}`) .auth(this.username, this.password) .set("User-Agent", `Hyperwallet Node SDK v${this.version}`) .type(contentType) @@ -178,7 +178,7 @@ export default class ApiClient { /** * Do a GET call to the Hyperwallet API server * - * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v3/`) + * @param {string} partialUrl - The api endpoint to call (gets prefixed by `server` and `/rest/v4/`) * @param {Object} params - Query parameters to send in this call * @param {api-callback} callback - The callback for this call */ @@ -191,7 +191,7 @@ export default class ApiClient { this.createJoseJsonParser(); } request - .get(`${this.server}/rest/v3/${partialUrl}`) + .get(`${this.server}/rest/v4/${partialUrl}`) .auth(this.username, this.password) .set("User-Agent", `Hyperwallet Node SDK v${this.version}`) .type(contentType) diff --git a/test/Hyperwallet.spec.js b/test/Hyperwallet.spec.js index 0fc36ea..f746cb8 100644 --- a/test/Hyperwallet.spec.js +++ b/test/Hyperwallet.spec.js @@ -19,7 +19,6 @@ describe("Hyperwallet", () => { username: "test-username", password: "test-password", }); - client.client.username.should.be.equal("test-username"); client.client.password.should.be.equal("test-password"); client.client.server.should.be.equal("https://api.sandbox.hyperwallet.com"); @@ -248,17 +247,20 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listUsers} */ it("should do get call with options", () => { const callback = () => null; - client.listUsers({ test: "value" }, callback); - + client.listUsers({ clientUserId: "test-client-user-id", status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users", { clientUserId: "test-client-user-id", status: "test-status" }); }); + /** @test {Hyperwallet#listUsers} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listUsers({ test1: "value" }, callback)).to.throw("Invalid Filter. Expected - clientUserId,email,programToken,status,verificationStatus"); + }); /** @test {Hyperwallet#listUsers} */ it("should do get call without options", () => { const callback = () => null; client.listUsers({}, callback); - apiClientSpy.should.have.been.calledOnce(); apiClientSpy.should.have.been.calledWith("users", {}); }); @@ -267,7 +269,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -563,18 +567,23 @@ describe("Hyperwallet", () => { }); /** @test {Hyperwallet#listUserStatusTransitions} */ - it("should throw error if userToken is missing", () => { + it("should do get call with options", () => { const callback = () => null; - expect(() => client.listUserStatusTransitions(undefined, {}, callback)).to.throw("userToken is required"); + client.listUserStatusTransitions("test-user-token", { transition: "test-transition" }, callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/status-transitions", { transition: "test-transition" }); }); /** @test {Hyperwallet#listUserStatusTransitions} */ - it("should do get call with options", () => { + it("should throw error for invalid filter", () => { const callback = () => null; - client.listUserStatusTransitions("test-user-token", { test: "value" }, callback); + expect(() => client.listUserStatusTransitions("test-user-token", { test1: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); + }); - apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/status-transitions", { test: "value" }); + /** @test {Hyperwallet#listUserStatusTransitions} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listUserStatusTransitions(undefined, {}, callback)).to.throw("userToken is required"); }); /** @test {Hyperwallet#listUserStatusTransitions} */ @@ -590,7 +599,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -792,10 +803,16 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listBankCards} */ it("should do get call with options", () => { const callback = () => null; - client.listBankCards("test-user-token", { test: "value" }, callback); + client.listBankCards("test-user-token", { status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-cards", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-cards", { status: "test-status" }); + }); + + /** @test {Hyperwallet#listBankCards} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBankCards("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - status"); }); /** @test {Hyperwallet#listBankCards} */ @@ -811,7 +828,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -989,10 +1008,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listBankCardStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listBankCardStatusTransitions("test-user-token", "test-bank-card-token", { test: "value" }, callback); - + client.listBankCardStatusTransitions("test-user-token", "test-bank-card-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-cards/test-bank-card-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-cards/test-bank-card-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listBankCardStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBankCardStatusTransitions("test-user-token", "test-bank-card-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listBankCardStatusTransitions} */ @@ -1008,7 +1032,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1206,10 +1232,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPaperChecks} */ it("should do get call with options", () => { const callback = () => null; - client.listPaperChecks("test-user-token", { test: "value" }, callback); - + client.listPaperChecks("test-user-token", { status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/paper-checks", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paper-checks", { status: "test-status" }); + }); + + /** @test {Hyperwallet#listPaperChecks} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPaperChecks("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - status"); }); /** @test {Hyperwallet#listPaperChecks} */ @@ -1225,7 +1256,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1403,10 +1436,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPaperCheckStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listPaperCheckStatusTransitions("test-user-token", "test-paper-check-token", { test: "value" }, callback); - + client.listPaperCheckStatusTransitions("test-user-token", "test-paper-check-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/paper-checks/test-paper-check-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paper-checks/test-paper-check-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listPaperCheckStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPaperCheckStatusTransitions("test-user-token", "test-paper-check-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listPaperCheckStatusTransitions} */ @@ -1422,7 +1460,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1553,10 +1593,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listTransfers} */ it("should do get call with options", () => { const callback = () => null; - client.listTransfers({ test: "value" }, callback); - + client.listTransfers({ clientTransferId: "test-status", sourceToken: "test-sourceToken", destinationToken: "test-destinationToken" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("transfers", { test: "value" }); + apiClientSpy.should.have.been.calledWith("transfers", { clientTransferId: "test-status", sourceToken: "test-sourceToken", destinationToken: "test-destinationToken" }); + }); + + /** @test {Hyperwallet#listTransfers} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listTransfers({ test: "value" }, callback)).to.throw("Invalid Filter. Expected - clientTransferId,sourceToken,destinationToken"); }); /** @test {Hyperwallet#listTransfers} */ @@ -1572,7 +1617,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1759,7 +1806,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1906,17 +1955,21 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPayPalAccounts} */ it("should do get call with options", () => { const callback = () => null; - client.listPayPalAccounts("test-user-token", { test: "value" }, callback); - + client.listPayPalAccounts("test-user-token", { status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts", { status: "test-status" }); + }); + + /** @test {Hyperwallet#listPayPalAccounts} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPayPalAccounts("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - status"); }); /** @test {Hyperwallet#listPayPalAccounts} */ it("should do get call without options", () => { const callback = () => null; client.listPayPalAccounts("test-user-token", {}, callback); - apiClientSpy.should.have.been.calledOnce(); apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts", {}); }); @@ -1925,7 +1978,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -1942,6 +1997,128 @@ describe("Hyperwallet", () => { }); }); + /** @test {Hyperwallet#updatePayPalAccount} */ + describe("updatePayPalAccount()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPut: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#updatePayPalAccount} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.updatePayPalAccount(undefined, undefined, { test: "value" }, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#updatePayPalAccount} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.updatePayPalAccount("test-user-token", undefined, { test: "value" }, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#updatePayPalAccount} */ + it("should do put call to paypal account endpoint", () => { + const callback = () => null; + client.updatePayPalAccount("test-user-token", "test-paypal-account-token", { + test: "value", + }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token", { + test: "value", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#activatePayPalAccount} */ + describe("activatePayPalAccount()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#activatePayPalAccount} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.activatePayPalAccount(undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#activatePayPalAccount} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.activatePayPalAccount("test-user-token", undefined, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#activatePayPalAccount} */ + it("should send transition to 'ACTIVATED'", () => { + const callback = () => null; + client.activatePayPalAccount("test-user-token", "test-paypal-account-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", { + transition: "ACTIVATED", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#deactivatePayPalAccount} */ + describe("deactivatePayPalAccount()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#deactivatePayPalAccount} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.deactivatePayPalAccount(undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#deactivatePayPalAccount} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.deactivatePayPalAccount("test-user-token", undefined, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#deactivatePayPalAccount} */ + it("should send transition to 'DE_ACTIVATED'", () => { + const callback = () => null; + client.deactivatePayPalAccount("test-user-token", "test-paypal-account-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", { + transition: "DE_ACTIVATED", + }, {}, callback); + }); + }); + /** @test {Hyperwallet#createPayPalAccountStatusTransition} */ describe("createPayPalAccountStatusTransition()", () => { let client; @@ -1982,6 +2159,118 @@ describe("Hyperwallet", () => { }); }); + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + describe("getPayPalAccountStatusTransition()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition(undefined, undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition("test-user-token", undefined, undefined, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if statusTransitionToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", undefined, callback)).to.throw("statusTransitionToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should do get call if userToken, payPalAccountToken and statusTransitionToken is provided", () => { + const callback = () => null; + client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", "status-transition-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions/status-transition-token", {}, callback); + }); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + describe("listPayPalAccountStatusTransitions()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listPayPalAccountStatusTransitions(undefined, undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.listPayPalAccountStatusTransitions("test-user-token", undefined, {}, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should do get call with options", () => { + const callback = () => null; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", { test: "value" }); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should do get call without options", () => { + const callback = () => null; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {}); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + cb(); + }; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {}); + + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); + //-------------------------------------- // Prepaid Cards //-------------------------------------- @@ -2127,10 +2416,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPrepaidCards} */ it("should do get call with options", () => { const callback = () => null; - client.listPrepaidCards("test-user-token", { test: "value" }, callback); - + client.listPrepaidCards("test-user-token", { status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/prepaid-cards", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/prepaid-cards", { status: "test-status" }); + }); + + /** @test {Hyperwallet#listPrepaidCards} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPrepaidCards("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - status"); }); /** @test {Hyperwallet#listPrepaidCards} */ @@ -2146,7 +2440,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2350,10 +2646,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPrepaidCardStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listPrepaidCardStatusTransitions("test-user-token", "test-prepaid-card-token", { test: "value" }, callback); - + client.listPrepaidCardStatusTransitions("test-user-token", "test-prepaid-card-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/prepaid-cards/test-prepaid-card-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/prepaid-cards/test-prepaid-card-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listPrepaidCardStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPrepaidCardStatusTransitions("test-user-token", "test-prepaid-card-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listPrepaidCardStatusTransitions} */ @@ -2369,7 +2670,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2527,30 +2830,34 @@ describe("Hyperwallet", () => { const callback = () => null; expect(() => client.listBankAccounts(undefined, {}, callback)).to.throw("userToken is required"); }); - /** @test {Hyperwallet#listBankAccounts} */ it("should do get call with options", () => { const callback = () => null; - client.listBankAccounts("test-user-token", { test: "value" }, callback); - + client.listBankAccounts("test-user-token", { type: "test-type", status: "test-status" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-accounts", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-accounts", { type: "test-type", status: "test-status" }); + }); + + /** @test {Hyperwallet#listBankAccounts} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBankAccounts("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - type,status"); }); /** @test {Hyperwallet#listBankAccounts} */ it("should do get call without options", () => { const callback = () => null; client.listBankAccounts("test-user-token", {}, callback); - apiClientSpy.should.have.been.calledOnce(); apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-accounts", {}); }); - /** @test {Hyperwallet#listBankAccounts} */ it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2712,7 +3019,6 @@ describe("Hyperwallet", () => { const callback = () => null; expect(() => client.listBankAccountStatusTransitions(undefined, undefined, {}, callback)).to.throw("userToken is required"); }); - /** @test {Hyperwallet#listBankAccountStatusTransitions} */ it("should throw error if bankAccountToken is missing", () => { const callback = () => null; @@ -2722,10 +3028,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listBankAccountStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listBankAccountStatusTransitions("test-user-token", "test-bank-account-token", { test: "value" }, callback); - + client.listBankAccountStatusTransitions("test-user-token", "test-bank-account-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-accounts/test-bank-account-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/bank-accounts/test-bank-account-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listBankAccountStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBankAccountStatusTransitions("test-user-token", "test-bank-account-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listBankAccountStatusTransitions} */ @@ -2741,7 +3052,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2787,10 +3100,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listBalancesForUser} */ it("should do get call with options", () => { const callback = () => null; - client.listBalancesForUser("test-user-token", { test: "value" }, callback); - + client.listBalancesForUser("test-user-token", { currency: "test-currency" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/balances", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/balances", { currency: "test-currency" }); + }); + + /** @test {Hyperwallet#listBalancesForUser} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBalancesForUser("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - currency"); }); /** @test {Hyperwallet#listBalancesForUser} */ @@ -2806,7 +3124,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2873,7 +3193,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -2940,7 +3262,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3058,14 +3382,19 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPayments} */ it("should do get call with options", () => { const callback = () => null; - client.listPayments({ test: "value" }, callback); - + client.listPayments({ clientPaymentId: "test-client-payment-id" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("payments", { test: "value" }); + apiClientSpy.should.have.been.calledWith("payments", { clientPaymentId: "test-client-payment-id" }); }); /** @test {Hyperwallet#listPayments} */ - it("should do get call without options", () => { + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPayments({ test: "value" }, callback)).to.throw("Invalid Filter. Expected - clientPaymentId"); + }); + + /** @test {Hyperwallet#listPayments} */ + it("should do get call without options", () => { const callback = () => null; client.listPayments({}, callback); @@ -3077,7 +3406,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3191,10 +3522,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listPaymentStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listPaymentStatusTransitions("test-payment-token", { test: "value" }, callback); - + client.listPaymentStatusTransitions("test-payment-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("payments/test-payment-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("payments/test-payment-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listPaymentStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listPaymentStatusTransitions("test-payment-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listPaymentStatusTransitions} */ @@ -3210,7 +3546,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3396,13 +3734,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listTransferMethodConfigurations} */ it("should do get call with options", () => { const callback = () => null; - client.listTransferMethodConfigurations("test-user-token", { test: "value" }, callback); - + client.listTransferMethodConfigurations("test-user-token", { userToken: "test-userToken" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("transfer-method-configurations", { - test: "value", - userToken: "test-user-token", - }); + apiClientSpy.should.have.been.calledWith("transfer-method-configurations", { userToken: "test-user-token" }); + }); + + /** @test {Hyperwallet#listTransferMethodConfigurations} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listTransferMethodConfigurations("test-user-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - userToken"); }); /** @test {Hyperwallet#listTransferMethodConfigurations} */ @@ -3420,7 +3760,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3538,7 +3880,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3599,7 +3943,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3666,7 +4012,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3705,10 +4053,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listWebhookNotifications} */ it("should do get call with options", () => { const callback = () => null; - client.listWebhookNotifications({ test: "value" }, callback); - + client.listWebhookNotifications({ programToken: "test-programToken", type: "test-type" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("webhook-notifications", { test: "value" }); + apiClientSpy.should.have.been.calledWith("webhook-notifications", { programToken: "test-programToken", type: "test-type" }); + }); + + /** @test {Hyperwallet#listWebhookNotifications} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listWebhookNotifications({ test: "value" }, callback)).to.throw("Invalid Filter. Expected - programToken,type"); }); /** @test {Hyperwallet#listWebhookNotifications} */ @@ -3724,7 +4077,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -3871,7 +4226,9 @@ describe("Hyperwallet", () => { expect(err).to.be.undefined(); data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); res.should.be.deep.equal(providedRes); @@ -4013,7 +4370,6 @@ describe("Hyperwallet", () => { it("should do get call with options", () => { const callback = () => null; client.listVenmoAccounts("test-user-token", { test: "value" }, callback); - apiClientSpy.should.have.been.calledOnce(); apiClientSpy.should.have.been.calledWith("users/test-user-token/venmo-accounts", { test: "value" }); }); @@ -4031,7 +4387,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -4246,10 +4604,15 @@ describe("Hyperwallet", () => { /** @test {Hyperwallet#listVenmoAccountStatusTransitions} */ it("should do get call with options", () => { const callback = () => null; - client.listVenmoAccountStatusTransitions("test-user-token", "test-venmo-account-token", { test: "value" }, callback); - + client.listVenmoAccountStatusTransitions("test-user-token", "test-venmo-account-token", { transition: "test-transition" }, callback); apiClientSpy.should.have.been.calledOnce(); - apiClientSpy.should.have.been.calledWith("users/test-user-token/venmo-accounts/test-venmo-account-token/status-transitions", { test: "value" }); + apiClientSpy.should.have.been.calledWith("users/test-user-token/venmo-accounts/test-venmo-account-token/status-transitions", { transition: "test-transition" }); + }); + + /** @test {Hyperwallet#listVenmoAccountStatusTransitions} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listVenmoAccountStatusTransitions("test-user-token", "test-venmo-account-token", { test: "value" }, callback)).to.throw("Invalid Filter. Expected - transition"); }); /** @test {Hyperwallet#listVenmoAccountStatusTransitions} */ @@ -4265,7 +4628,9 @@ describe("Hyperwallet", () => { it("should handle 204 return", (cb) => { const callback = (err, data) => { data.should.be.deep.equal({ - count: 0, + hasNextPage: false, + hasPreviousPage: false, + limit: 0, data: [], }); @@ -4281,4 +4646,589 @@ describe("Hyperwallet", () => { }); }); }); + + //-------------------------------------- + // Business StakeHolder + //-------------------------------------- + + /** @test {Hyperwallet#createBusinessStakeholder} */ + describe("createBusinessStakeholder()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#createStakeholder} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.createBusinessStakeholder(undefined, { test: "value" }, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#createStakeholder} */ + it("should send post call to Stakeholder status transition endpoint", () => { + const callback = () => null; + client.createBusinessStakeholder("test-user-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders", { + test: "value", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + describe("listBusinessStakeholders()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listBusinessStakeholders(undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + it("should do get call with options", () => { + const callback = () => null; + client.listBusinessStakeholders("test-user-token", { status: "test-status", isBusinessContact: "test-isBusinessContact", + isDirector: "test-isDirector", isUltimateBeneficialOwner: "test-isUltimateBeneficialOwner" }, callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders", { status: "test-status", isBusinessContact: "test-isBusinessContact", + isDirector: "test-isDirector", isUltimateBeneficialOwner: "test-isUltimateBeneficialOwner" }); + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + it("should throw error for invalid filter", () => { + const callback = () => null; + expect(() => client.listBusinessStakeholders("test-user-token", { test: "value" }, callback)). + to.throw("Invalid Filter. Expected - status,isBusinessContact,isDirector,isUltimateBeneficialOwner"); + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + it("should do get call without options", () => { + const callback = () => null; + client.listBusinessStakeholders("test-user-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders", {}); + }); + + /** @test {Hyperwallet#listBusinessStakeholders} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + + cb(); + }; + client.listBusinessStakeholders("test-user-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders", {}); + + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); + + /** @test {Hyperwallet#updateBusinessStakeholder} */ + describe("updateBusinessStakeholder()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPut: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#updateBusinessStakeholder} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.updateBusinessStakeholder(undefined, undefined, { test: "value" }, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#updateBusinessStakeholder} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.updateBusinessStakeholder("test-user-token", undefined, { test: "value" }, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#updateBusinessStakeholder} */ + it("should do put call to Stakeholder endpoint", () => { + const callback = () => null; + client.updateBusinessStakeholder("test-user-token", "test-stakeholder-token", { + test: "value", + }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token", { + test: "value", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#deactivateBusinessStakeholder} */ + describe("deactivateBusinessStakeholder()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#deactivateBusinessStakeholder} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.deactivateBusinessStakeholder(undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#deactivateBusinessStakeholder} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.deactivateBusinessStakeholder("test-user-token", undefined, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#deactivateBusinessStakeholder} */ + it("should send transition to 'DE-ACTIVATED'", () => { + const callback = () => null; + client.deactivateBusinessStakeholder("test-user-token", "test-stakeholder-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", { + transition: "DE_ACTIVATED", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#activateBusinessStakeholder} */ + describe("activateBusinessStakeholder()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#activateBusinessStakeholder} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.activateBusinessStakeholder(undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#activateBusinessStakeholder} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.activateBusinessStakeholder("test-user-token", undefined, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#activateBusinessStakeholder} */ + it("should send transition to 'ACTIVATED'", () => { + const callback = () => null; + client.activateBusinessStakeholder("test-user-token", "test-stakeholder-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", { + transition: "ACTIVATED", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#createBusinessStakeholderStatusTransition} */ + describe("createBusinessStakeholderStatusTransition()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#createBusinessStakeholderStatusTransition} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.createBusinessStakeholderStatusTransition(undefined, undefined, { test: "value" }, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#createBusinessStakeholderStatusTransition} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.createBusinessStakeholderStatusTransition("test-user-token", undefined, { test: "value" }, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#createBusinessStakeholderStatusTransition} */ + it("should send post call to StakeHolder status transition endpoint", () => { + const callback = () => null; + client.createBusinessStakeholderStatusTransition("test-user-token", "test-stakeholder-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", { + test: "value", + }, {}, callback); + }); + }); + + /** @test {Hyperwallet#getBusinessStakeholderStatusTransition} */ + describe("getBusinessStakeholderStatusTransition()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#getBusinessStakeholderStatusTransition} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.getBusinessStakeholderStatusTransition(undefined, undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#getBusinessStakeholderStatusTransition} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.getBusinessStakeholderStatusTransition("test-user-token", undefined, undefined, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#getBusinessStakeholderStatusTransition} */ + it("should throw error if statusTransitionToken is missing", () => { + const callback = () => null; + expect(() => client.getBusinessStakeholderStatusTransition("test-user-token", "test-stakeholder-token", undefined, callback)).to.throw("statusTransitionToken is required"); + }); + + /** @test {Hyperwallet#getBusinessStakeholderStatusTransition} */ + it("should do get call if userToken, stakeholderToken and statusTransitionToken is provided", () => { + const callback = () => null; + client.getBusinessStakeholderStatusTransition("test-user-token", "test-stakeholder-token", "status-transition-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions/status-transition-token", {}, callback); + }); + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + describe("listBusinessStakeholderStatusTransitions()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listBusinessStakeholderStatusTransitions(undefined, undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.listBusinessStakeholderStatusTransitions("test-user-token", undefined, {}, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + it("should do get call with options", () => { + const callback = () => null; + client.listBusinessStakeholderStatusTransitions("test-user-token", "test-stakeholder-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", { test: "value" }); + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + it("should do get call without options", () => { + const callback = () => null; + client.listBusinessStakeholderStatusTransitions("test-user-token", "test-stakeholder-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", {}); + }); + + /** @test {Hyperwallet#listBusinessStakeholderStatusTransitions} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + + cb(); + }; + client.listBusinessStakeholderStatusTransitions("test-user-token", "test-stakeholder-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/business-stakeholders/test-stakeholder-token/status-transitions", {}); + + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); + + describe("uploadBusinessStakeholderDocuments()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPutMultipart: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#uploadBusinessStakeholderDocuments} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.uploadBusinessStakeholderDocuments(undefined, undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#uploadBusinessStakeholderDocuments} */ + it("should throw error if stakeholderToken is missing", () => { + const callback = () => null; + expect(() => client.uploadBusinessStakeholderDocuments("test-user-token", undefined, {}, callback)).to.throw("stakeholderToken is required"); + }); + + /** @test {Hyperwallet#uploadBusinessStakeholderDocuments} */ + it("should throw error if data is missing", () => { + const callback = () => null; + expect(() => client.uploadBusinessStakeholderDocuments("test-user-token", "test-stakeholder-token", null, callback)).to.throw("Files for upload are require"); + }); + + /** @test {Hyperwallet#uploadBusinessStakeholderDocuments} */ + it("should do put call to upload multipart", () => { + const callback = () => null; + + client.uploadBusinessStakeholderDocuments("users/test-user-token", "test-stakeholder-token", { + test: "value", + }, callback); + + apiClientSpy.should.have.been.calledOnce(); + }); + }); + + /** @test {Hyperwallet#listTransferMethods} */ + describe("listTransferMethods()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listTransferMethods} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listTransferMethods(undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#listTransferMethods} */ + it("should do get call with options", () => { + const callback = () => null; + client.listTransferMethods("test-user-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", { test: "value" }); + }); + + /** @test {Hyperwallet#listTransferMethods} */ + it("should do get call without options", () => { + const callback = () => null; + client.listTransferMethods("test-user-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", {}); + }); + + /** @test {Hyperwallet#listTransferMethods} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + + cb(); + }; + client.listTransferMethods("test-user-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", {}); + + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); + + /** @test {Hyperwallet#getTransferStatusTransition} */ + describe("getTransferStatusTransition()", () => { + let client; + let apiClientSpy; + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#getTransferStatusTransition} */ + it("should throw error if transferToken is missing", () => { + const callback = () => null; + expect(() => client.getTransferStatusTransition(undefined, undefined, callback)).to.throw("transferToken is required"); + }); + + /** @test {Hyperwallet#getTransferStatusTransition} */ + it("should throw error if statusTransitionToken is missing", () => { + const callback = () => null; + expect(() => client.getTransferStatusTransition("test-transfer-token", undefined, callback)).to.throw("statusTransitionToken is required"); + }); + + /** @test {Hyperwallet#getTransferStatusTransition} */ + it("should do get call if transferToken and statusTransitionToken is provided", () => { + const callback = () => null; + client.getTransferStatusTransition("test-transfer-token", "test-status-transition-token", callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("transfers/test-transfer-token/status-transitions/test-status-transition-token", {}, callback); + }); + }); + + /** @test {Hyperwallet#listTransferStatusTransition} */ + describe("listTransferStatusTransition()", () => { + let client; + let apiClientSpy; + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listTransferStatusTransition} */ + it("should throw error if transferToken is missing", () => { + const callback = () => null; + expect(() => client.listTransferStatusTransition(undefined, {}, callback)).to.throw("transferToken is required"); + }); + + /** @test {Hyperwallet#listTransferStatusTransition} */ + it("should do get call with options", () => { + const callback = () => null; + client.listTransferStatusTransition("test-transfer-token", { test: "value" }, callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("transfers/test-transfer-token/status-transitions", { test: "value" }); + }); + + /** @test {Hyperwallet#listTransferStatusTransition} */ + it("should do get call without options", () => { + const callback = () => null; + client.listTransferStatusTransition("test-transfer-token", {}, callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("transfers/test-transfer-token/status-transitions", {}); + }); + + /** @test {Hyperwallet#listTransferStatusTransition} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + cb(); + }; + client.listTransferStatusTransition("test-transfer-token", {}, callback); + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("transfers/test-transfer-token/status-transitions", {}); + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); }); diff --git a/test/utils/ApiClient.spec.js b/test/utils/ApiClient.spec.js index 3e6618a..3debee4 100644 --- a/test/utils/ApiClient.spec.js +++ b/test/utils/ApiClient.spec.js @@ -59,7 +59,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .post("/rest/v3/test", { + .post("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -85,7 +85,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .post("/rest/v3/test", { + .post("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -113,7 +113,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .post("/rest/v3/test", { + .post("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -141,7 +141,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .post("/rest/v3/test", { + .post("/rest/v4/test", { test: "value", }) .reply(201, { response: "value" }, { "Content-Type": "application/json" }); @@ -181,7 +181,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .post("/rest/v3/test", { + .post("/rest/v4/test", { test: "value", }) .reply(404, { @@ -395,7 +395,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .put("/rest/v3/test", { + .put("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -421,7 +421,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .put("/rest/v3/test", { + .put("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -449,7 +449,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .put("/rest/v3/test", { + .put("/rest/v4/test", { test: "value", }) .query({ sort: "test" }) @@ -477,7 +477,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .put("/rest/v3/test", { + .put("/rest/v4/test", { test: "value", }) .reply(200, { response: "value" }, { "Content-Type": "application/json" }); @@ -517,7 +517,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "application/json") - .put("/rest/v3/test", { + .put("/rest/v4/test", { test: "value", }) .reply(404, { @@ -792,7 +792,7 @@ describe("utils/ApiClient", () => { .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") .matchHeader("Content-Type", "multipart/form-data") - .put("/rest/v3/test", { test: "value" }) + .put("/rest/v4/test", { test: "value" }) .reply(400, [] , { "Content-Type": "application/jose+json" }); @@ -885,7 +885,7 @@ describe("utils/ApiClient", () => { .matchHeader("Authorization", authHeader) .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") - .get("/rest/v3/test") + .get("/rest/v4/test") .query({ sort: "test" }) .reply(200, { response: "value" }, { "Content-Type": "application/json" }); @@ -908,7 +908,7 @@ describe("utils/ApiClient", () => { .matchHeader("Authorization", authHeader) .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") - .get("/rest/v3/test") + .get("/rest/v4/test") .query({ sort: "test" }) .reply(200, { response: "value" }, { "Content-Type": "application/json;charset=utf-8", @@ -933,7 +933,7 @@ describe("utils/ApiClient", () => { .matchHeader("Authorization", authHeader) .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") - .get("/rest/v3/test") + .get("/rest/v4/test") .query({ sort: "test" }) .reply(200, { response: "value" }, { "Content-Type": "charset=utf-8;application/json", @@ -958,7 +958,7 @@ describe("utils/ApiClient", () => { .matchHeader("Authorization", authHeader) .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") - .get("/rest/v3/test") + .get("/rest/v4/test") .reply(200, { response: "value" }, { "Content-Type": "application/json" }); client.doGet("test", {}, (err, body, res) => { @@ -995,7 +995,7 @@ describe("utils/ApiClient", () => { .matchHeader("Authorization", authHeader) .matchHeader("User-Agent", `Hyperwallet Node SDK v${packageJson.version}`) .matchHeader("Accept", "application/json") - .get("/rest/v3/test") + .get("/rest/v4/test") .reply(404, { errors: [{ message: "message",