-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from stripe/remi-add-person
Add support for the Person resource
- Loading branch information
Showing
5 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|