Skip to content

Commit

Permalink
Add support for the Person resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 27, 2018
1 parent 278b07d commit 4958429
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/resources/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,39 @@ module.exports = StripeResource.extend({
path: 'accounts/{accountId}/login_links',
urlParams: ['accountId'],
}),

/**
* Accounts: Person methods
*/

createPerson: stripeMethod({
method: 'POST',
path: 'accounts/{accountId}/persons',
urlParams: ['accountId'],
}),

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

retrievePerson: stripeMethod({
method: 'GET',
path: 'accounts/{accountId}/persons/{personId}',
urlParams: ['accountId', 'personId'],
}),

updatePerson: stripeMethod({
method: 'POST',
path: 'accounts/{accountId}/persons/{personId}',
urlParams: ['accountId', 'personId'],
}),

deletePerson: stripeMethod({
method: 'DELETE',
path: 'accounts/{accountId}/persons/{personId}',
urlParams: ['accountId', 'personId'],
}),
});
21 changes: 21 additions & 0 deletions lib/resources/Persons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

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

/**
* Persons is a unique resource in that, upon instantiation,
* requires an accountId, and therefore each of its methods only
* require the personId argument.
*
* This streamlines the API specifically for the case of accessing person
* on a returned transfer object.
*
* E.g. accountObject.person.retrieve(personId)
* (As opposed to the also-supported stripe.accounts.retrievePerson(accountId,
* personId))
*/
module.exports = StripeResource.extend({
path: 'accounts/{accountId}/persons',
includeBasic: ['create', 'del', 'list', 'retrieve', 'update'],
});

1 change: 1 addition & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var resources = {
ChargeRefunds: require('./resources/ChargeRefunds'),
CustomerCards: require('./resources/CustomerCards'),
CustomerSubscriptions: require('./resources/CustomerSubscriptions'),
Persons: require('./resources/Persons'),
TransferReversals: require('./resources/TransferReversals'),

// Namespaced resources
Expand Down
112 changes: 112 additions & 0 deletions test/resources/Account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,116 @@ describe('Account Resource', function() {
});
});
});

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

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

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

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

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

describe('deletePerson', function() {
it('Sends the correct request', function() {
stripe.account.deletePerson('acct_123', 'person_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/accounts/acct_123/persons/person_123',
headers: {},
data: {},
});
});

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

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

it('Sends the correct request [with specified auth]', function() {
stripe.account.listPersons('acct_123', TEST_AUTH_KEY);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/accounts/acct_123/persons',
headers: {},
data: {},
auth: TEST_AUTH_KEY,
});
});
});
});
});
84 changes: 84 additions & 0 deletions test/resources/Persons.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'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 PERSON_TEST_ID = 'person_123';

// Create new Person instance with pre-filled accountId:
var person = new resources.Persons(
stripe,
{accountId: ACCOUNT_TEST_ID}
);

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

describe('Person Resource', function() {
describe('create', function() {
it('Sends the correct request', function() {
person.create({
first_name: 'John',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons',
data: {first_name: 'John'},
headers: {},
});
});
});

describe('delete', function() {
it('Sends the correct request', function() {
person.del(PERSON_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'DELETE',
url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons/' + PERSON_TEST_ID,
data: {},
headers: {},
});
});
});

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

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

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

0 comments on commit 4958429

Please sign in to comment.