Skip to content

Commit

Permalink
Add date inequality support (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
JenniferMah authored and childish-sambino committed Aug 8, 2019
1 parent 072b4cd commit 371b930
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
21 changes: 14 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/services/open-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ class OpenApiClient {
getParams(opts, operation) {
const params = {};
operation.parameters.forEach(parameter => {
const replaceSymbolName = parameter.name.replace('>', 'After').replace('<', 'Before');
// 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)) {
let value = opts.data[parameter.name];

if (parameter.in === 'query' && doesObjectHaveProperty(opts.data, replaceSymbolName)) {
let value = opts.data[replaceSymbolName];
if (parameter.schema.type === 'boolean') {
value = value.toString();
}

params[parameter.name] = value;
}
});
Expand Down
40 changes: 40 additions & 0 deletions test/services/twilio-api/twilio-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ describe('services', () => {
expect(response).to.eql([{ sid: callSid }, { sid: callSid }]);
});

test
.nock('https://api.twilio.com', api => {
/* eslint-disable camelcase */
api.get(`/2010-04-01/Accounts/${accountSid}/Calls.json?StartTime%3E=${callStartTime}`).reply(200, {
calls: [{
sid: callSid
}]
});
/* eslint-enable camelcase */
})
.it('test greater than inequality conversion', async () => {
const response = await client.list({
domain: 'api',
path: '/2010-04-01/Accounts/{AccountSid}/Calls.json',
data: { startTimeAfter: callStartTime } // CLI is startTimeAfter
});

expect(response).to.eql([{ sid: callSid }]);
});

test
.nock('https://api.twilio.com', api => {
/* eslint-disable camelcase */
api.get(`/2010-04-01/Accounts/${accountSid}/Calls.json?StartTime%3C=${callStartTime}`).reply(200, {
calls: [{
sid: callSid
}]
});
/* eslint-enable camelcase */
})
.it('test less than inequality conversion', async () => {
const response = await client.list({
domain: 'api',
path: '/2010-04-01/Accounts/{AccountSid}/Calls.json',
data: { startTimeBefore: callStartTime } // CLI is startTimeBefore
});

expect(response).to.eql([{ sid: callSid }]);
});

test
.nock('https://studio.twilio.com', api => {
/* eslint-disable camelcase */
Expand Down

0 comments on commit 371b930

Please sign in to comment.