From 654c72304beb4a10db8723eed2e51b62de8671bb Mon Sep 17 00:00:00 2001 From: Jonathan Lomas Date: Tue, 1 May 2018 16:24:55 -0700 Subject: [PATCH] Fix UsageRecords so it passes through the rest of the arguments --- lib/resources/UsageRecords.js | 14 +++++++--- test/resources/UsageRecords.spec.js | 42 +++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/lib/resources/UsageRecords.js b/lib/resources/UsageRecords.js index 8230549467..c1871f621f 100644 --- a/lib/resources/UsageRecords.js +++ b/lib/resources/UsageRecords.js @@ -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); } }); diff --git a/test/resources/UsageRecords.spec.js b/test/resources/UsageRecords.spec.js index f14cac308a..fbac729953 100644 --- a/test/resources/UsageRecords.spec.js +++ b/test/resources/UsageRecords.spec.js @@ -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); + }); + }); }); });