From 90b970bcb29c5106b66f1bc5e1730070940e27ea Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Mon, 8 Jul 2019 21:15:35 -0500 Subject: [PATCH] Convert boolean request parameter values to strings --- src/services/open-api-client.js | 8 +++++++- .../services/twilio-api/twilio-client.test.js | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/services/open-api-client.js b/src/services/open-api-client.js index debd451c..77c777d9 100644 --- a/src/services/open-api-client.js +++ b/src/services/open-api-client.js @@ -70,7 +70,13 @@ class OpenApiClient { // Build the actual request params from the spec's query parameters. This // effectively drops all params that are not in the spec. if (parameter.in === 'query' && doesObjectHaveProperty(opts.data, parameter.name)) { - params[parameter.name] = opts.data[parameter.name]; + let value = opts.data[parameter.name]; + + if (parameter.schema.type === 'boolean') { + value = value.toString(); + } + + params[parameter.name] = value; } }); diff --git a/test/services/twilio-api/twilio-client.test.js b/test/services/twilio-api/twilio-client.test.js index 70e68d02..1ab2e3b2 100644 --- a/test/services/twilio-api/twilio-client.test.js +++ b/test/services/twilio-api/twilio-client.test.js @@ -151,12 +151,29 @@ describe('services', () => { }); test - .it('handles bad domains', async () => { + .it('handles bad paths', async () => { await expect(client.create({ domain: 'api', path: '/2010-04-01/Accounts/{AccountSid}/AWESOME!!!!' })).to.be.rejectedWith('not found'); }); + + test + .nock('https://api.twilio.com', api => { + api.post(`/2010-04-01/Accounts/${accountSid}/Addresses.json`).reply(201, { + verified: 'true' + }); + }) + .it('handles boolean parameters', async () => { + const response = await client.create({ + domain: 'api', + path: '/2010-04-01/Accounts/{AccountSid}/Addresses.json', + data: { emergencyEnabled: true } + }); + + expect(response).to.eql({ verified: 'true' }); + expect(httpClient.lastRequest.formData).to.eql({ EmergencyEnabled: 'true' }); + }); }); }); });