From 968e5a6ccdf619ebf8c8b7fde10af0d8857d7b92 Mon Sep 17 00:00:00 2001 From: CJ Avilla Date: Tue, 3 Mar 2020 14:46:11 -0800 Subject: [PATCH] Improve args check to support optional params for makeRequest --- lib/makeRequest.js | 2 +- test/StripeResource.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/makeRequest.js b/lib/makeRequest.js index b266fd2dbf..14740f235b 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -33,7 +33,7 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { const options = utils.getOptionsFromArgs(args); // Validate that there are no more args. - if (args.length) { + if (args.filter((x) => x != null).length) { throw new Error( `Stripe: Unknown arguments (${args}). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to ${requestMethod} \`${path}\`)` ); diff --git a/test/StripeResource.spec.js b/test/StripeResource.spec.js index b6d01bbb31..5030727265 100644 --- a/test/StripeResource.spec.js +++ b/test/StripeResource.spec.js @@ -1,3 +1,4 @@ +sub_Gr5mwRHNEuSi1z 'use strict'; const utils = require('../testUtils'); @@ -77,6 +78,28 @@ describe('StripeResource', () => { }); }); + it('works correctly with undefined optional arguments', (done) => { + const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`) + .get('/v1/accounts/acct_123') + .reply(200, '{}'); + + realStripe.accounts.retrieve('acct_123', undefined, (err, response) => { + done(err); + scope.done(); + }); + }); + + it('works correctly with null optional arguments', (done) => { + const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`) + .get('/v1/accounts/acct_123') + .reply(200, '{}'); + + realStripe.accounts.retrieve('acct_123', null, (err, response) => { + done(err); + scope.done(); + }); + }); + it('encodes data for DELETE requests as query params', (done) => { const data = { foo: 'bar',