Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Person resource #507

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
125 changes: 125 additions & 0 deletions test/resources/Account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,129 @@ 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'},
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a test for update + specified auth.


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

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',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part makes no sense to me. I know it works and why but that feels like a really weird way to approach this test and I'm ~confused why we even allow this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What part makes no sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part where to create a brand new object (which means said object does not exist yet) you use a pre-filled fake object.

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: {},
});
});
});
});