Skip to content

Commit

Permalink
Improve args check to support optional params for makeRequest (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex-stripe authored Mar 6, 2020
1 parent 8042dcd commit 461d67b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/makeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}\`)`
);
Expand Down
22 changes: 22 additions & 0 deletions test/StripeResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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',
Expand Down

0 comments on commit 461d67b

Please sign in to comment.