Skip to content

Commit

Permalink
Add support for the Capability resource and APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed May 9, 2019
1 parent ea637ca commit 59c67d3
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/resources/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ module.exports = StripeResource.extend({
}
},

/**
* Accounts: Capability methods
*/

listCapabilities: stripeMethod({
method: 'GET',
path: 'accounts/{accountId}/capabilities',
urlParams: ['accountId'],
methodType: 'list',
}),

retrieveCapability: stripeMethod({
method: 'GET',
path: 'accounts/{accountId}/capabilities/{capabilityId}',
urlParams: ['accountId', 'capabilityId'],
}),

updateCapability: stripeMethod({
method: 'POST',
path: 'accounts/{accountId}/capabilities/{capabilityId}',
urlParams: ['accountId', 'capabilityId'],
}),

/**
* Accounts: External account methods
*/
Expand Down
9 changes: 9 additions & 0 deletions lib/resources/Capabilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

var StripeResource = require('../StripeResource');

module.exports = StripeResource.extend({
path: 'accounts/{accountId}/capabilities',
includeBasic: ['list', 'retrieve', 'update'],
});

1 change: 1 addition & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var resources = {

// The following rely on pre-filled IDs:
ApplicationFeeRefunds: require('./resources/ApplicationFeeRefunds'),
Capabilities: require('./resources/Capabilities'),
ChargeRefunds: require('./resources/ChargeRefunds'),
CustomerCards: require('./resources/CustomerCards'),
CustomerSubscriptions: require('./resources/CustomerSubscriptions'),
Expand Down
75 changes: 75 additions & 0 deletions test/resources/Account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,81 @@ describe('Account Resource', function() {
});
});

describe('Capability methods', function() {
describe('listCapabilities', function() {
it('Sends the correct request', function() {
stripe.account.listCapabilities('acct_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/acct_123/capabilities',
headers: {},
data: {},
});
});

it('Sends the correct request [with specified auth]', function() {
stripe.account.listCapabilities('acct_123', TEST_AUTH_KEY);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/acct_123/capabilities',
headers: {},
data: {},
auth: TEST_AUTH_KEY,
});
});
});

describe('retrieveCapability', function() {
it('Sends the correct request', function() {
stripe.account.retrieveCapability('acct_123', 'acap_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/acct_123/capabilities/acap_123',
headers: {},
data: {},
});
});

it('Sends the correct request [with specified auth]', function() {
stripe.account.retrieveCapability('acct_123', 'acap_123', TEST_AUTH_KEY);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/acct_123/capabilities/acap_123',
headers: {},
data: {},
auth: TEST_AUTH_KEY,
});
});
});

describe('updateCapability', function() {
it('Sends the correct request', function() {
stripe.account.updateCapability('acct_123', 'acap_123', {
first_name: 'John',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/acct_123/capabilities/acap_123',
headers: {},
data: {first_name: 'John'},
});
});

it('Sends the correct request [with specified auth]', function() {
stripe.account.updateCapability('acct_123', 'acap_123', {
first_name: 'John',
}, TEST_AUTH_KEY);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/acct_123/capabilities/acap_123',
headers: {},
data: {first_name: 'John'},
auth: TEST_AUTH_KEY,
});
});
});
});

describe('External account methods', function() {
describe('retrieveExternalAccount', function() {
it('Sends the correct request', function() {
Expand Down
58 changes: 58 additions & 0 deletions test/resources/Capabilities.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

var resources = require('../../lib/stripe').resources;
var stripe = require('../../testUtils').getSpyableStripe();
var expect = require('chai').expect;

var ACCOUNT_TEST_ID = 'acct_123';
var CAPABILITY_TEST_ID = 'acap_123';

// Create new Capability instance with pre-filled accountId:
var capability = new resources.Capabilities(
stripe,
{accountId: ACCOUNT_TEST_ID}
);

// Use spy from existing resource:
capability._request = stripe.customers._request;

describe('Capability Resource', function() {
describe('list', function() {
it('Sends the correct request', function() {
capability.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/capabilities',
data: {},
headers: {},
});
});
});

describe('retrieve', function() {
it('Sends the correct request', function() {
capability.retrieve(CAPABILITY_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/capabilities/' + CAPABILITY_TEST_ID,
data: {},
headers: {},
});
});
});

describe('update', function() {
it('Sends the correct request', function() {
capability.update(CAPABILITY_TEST_ID, {
first_name: 'John',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/capabilities/' + CAPABILITY_TEST_ID,
data: {first_name: 'John'},
headers: {},
});
});
});
});

0 comments on commit 59c67d3

Please sign in to comment.