Skip to content

Commit

Permalink
Convert boolean request parameter values to strings (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
childish-sambino committed Jul 9, 2019
1 parent 2041e7b commit 17a0da2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/services/open-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down
19 changes: 18 additions & 1 deletion test/services/twilio-api/twilio-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});
});
});

0 comments on commit 17a0da2

Please sign in to comment.