Skip to content

Commit

Permalink
Suport customBody in Resource#all
Browse files Browse the repository at this point in the history
  • Loading branch information
lubien committed Jul 27, 2016
1 parent cc76fc3 commit c8ee658
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Request {
opts.headers = this.headers;

if (this.customBody) {
opts.body = this.customBody;
opts.query = this.customBody;
} else if (hasBody) {
// The trick here is that some APIs throw when receive
// `Content-Type` header on POST and PUT
Expand Down
8 changes: 4 additions & 4 deletions src/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ export default class Resource {
/**
* @returns {Promise}
*/
static all() {
static all(customBody) {
const instance = new this();
return instance.getAll();
return instance.getAll(customBody);
}

/**
* @returns {Resource[]}
*/
getAll() {
return this.makeRequest('get')
getAll(customBody) {
return this.makeRequest('get', {customBody})
.then(response => {
const resources = this.factoryCollection(response);

Expand Down
12 changes: 12 additions & 0 deletions test/resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ test('Resource parents and childs', async t => {
.forEach(comment => t.is(comment.constructor, CommentResource));
});

test('Resource request custom body', async t => {
const comments = await CommentResource.all({
postId: 1
});

t.true(Array.isArray(comments));
t.true(
comments
.every(comment => comment.get('postId') === 1)
);
});

0 comments on commit c8ee658

Please sign in to comment.