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 654c723
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 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);
}
});
42 changes: 40 additions & 2 deletions test/resources/UsageRecords.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,57 @@ describe('UsageRecords Resource', function() {
stripe.usageRecords.create({
subscription_item: 'si_123',
quantity: 123,
timestmap: 123321,
timestamp: 123321,
action: 'increment'
});

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/subscription_items/si_123/usage_records',
headers: {},
data: {
quantity: 123,
timestmap: 123321,
timestamp: 123321,
action: 'increment'
}
});
});

it('Includes any options that were provided', function(done) {
stripe.usageRecords.create({
subscription_item: 'si_123',
quantity: 123,
timestamp: 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,
timestamp: 123321,
action: 'increment'
}
});

done();
});
});

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

0 comments on commit 654c723

Please sign in to comment.