-
Notifications
You must be signed in to change notification settings - Fork 751
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'], | ||
}); | ||
|
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', | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What part makes no sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: {}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
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.