Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9354f3c

Browse files
committedMay 1, 2018
Fix UsageRecords so it passes through the rest of the arguments
1 parent f12c3d6 commit 9354f3c

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed
 

‎lib/resources/UsageRecords.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ var stripeMethod = require('../StripeMethod');
44

55
module.exports = require('../StripeResource').extend({
66
path: 'subscription_items',
7-
create: function(args) {
8-
var requestPath = args.subscription_item + '/usage_records';
9-
var reqArgs = Object.assign({}, args);
7+
create: function() {
8+
var args = Array.prototype.slice.call(arguments);
9+
10+
var reqArgs = args.shift();
11+
var requestPath = reqArgs.subscription_item + '/usage_records';
12+
1013
delete reqArgs.subscription_item;
14+
15+
args.unshift(reqArgs);
16+
1117
return stripeMethod({
1218
method: 'POST',
1319
path: requestPath
14-
}).bind(this)(reqArgs);
20+
}).apply(this, args);
1521
}
1622
});

‎test/resources/UsageRecords.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('UsageRecords Resource', function() {
1212
timestmap: 123321,
1313
action: 'increment'
1414
});
15+
1516
expect(stripe.LAST_REQUEST).to.deep.equal({
1617
method: 'POST',
1718
url: '/v1/subscription_items/si_123/usage_records',
@@ -23,5 +24,42 @@ describe('UsageRecords Resource', function() {
2324
}
2425
});
2526
});
27+
28+
it('Includes any options that were provided', function(done) {
29+
stripe.usageRecords.create({
30+
subscription_item: 'si_123',
31+
quantity: 123,
32+
timestmap: 123321,
33+
action: 'increment'
34+
}, {
35+
stripe_account: 'acct_456',
36+
}).then(function(record) {
37+
expect(stripe.LAST_REQUEST).to.deep.equal({
38+
method: 'POST',
39+
url: '/v1/subscription_items/si_123/usage_records',
40+
headers: {
41+
"Stripe-Account": "acct_456"
42+
},
43+
data: {
44+
quantity: 123,
45+
timestmap: 123321,
46+
action: 'increment'
47+
}
48+
});
49+
50+
done();
51+
});
52+
});
53+
54+
it('Calls a given callback', function(done) {
55+
stripe.usageRecords.create({
56+
subscription_item: 'si_123',
57+
quantity: 123,
58+
timestmap: 123321,
59+
action: 'increment'
60+
}, function(error, record) {
61+
done(error);
62+
});
63+
});
2664
});
2765
});

0 commit comments

Comments
 (0)
Please sign in to comment.