Skip to content

Commit

Permalink
Fix UsageRecords so it passes through the rest of the arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jlomas-stripe committed May 1, 2018
1 parent f12c3d6 commit fe94fd8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/resources/UsageRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ var stripeMethod = require('../StripeMethod');

module.exports = require('../StripeResource').extend({
path: 'subscription_items',
create: function(args) {
var requestPath = args.subscription_item + '/usage_records';
var reqArgs = Object.assign({}, args);
create: function() {
var args = Array.prototype.slice.call(arguments);

var reqArgs = args.shift();
var requestPath = reqArgs.subscription_item + '/usage_records';

delete reqArgs.subscription_item;

args.unshift(reqArgs);

return stripeMethod({
method: 'POST',
path: requestPath
}).bind(this)(reqArgs);
}).apply(this, args);
}
});
38 changes: 38 additions & 0 deletions test/resources/UsageRecords.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('UsageRecords Resource', function() {
timestmap: 123321,
action: 'increment'
});

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_items/si_123/usage_records',
Expand All @@ -23,5 +24,42 @@ describe('UsageRecords Resource', function() {
}
});
});

it('Includes any options that were provided', function(done) {
stripe.usageRecords.create({
subscription_item: 'si_123',
quantity: 123,
timestmap: 123321,
action: 'increment'
}, {
stripe_account: 'acct_456',
}).then(function(record) {
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_items/si_123/usage_records',
headers: {
'Stripe-Account': 'acct_456'
},
data: {
quantity: 123,
timestmap: 123321,
action: 'increment'
}
});

done();
});
});

it('Calls a given callback', function(done) {
stripe.usageRecords.create({
subscription_item: 'si_123',
quantity: 123,
timestmap: 123321,
action: 'increment'
}, function(error, record) {
done(error);
});
});
});
});

0 comments on commit fe94fd8

Please sign in to comment.