Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert boolean request parameter values to strings #30

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should EmergencyEnabled be emergencyEnabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it gets PascalCased by the API client, which is what the API endpoint is expecting: https://www.twilio.com/docs/usage/api/address#create-an-address-resource

});
});
});
});