Skip to content

Commit

Permalink
fix status in query string to accept strings and numbers (#542)
Browse files Browse the repository at this point in the history
* fix CloseStatus value in query string

* fix unit test for query string builder

* consider both cases for status in buildquerystring

* run linter

* consider both cases for status in buildquerystring

* run linter
  • Loading branch information
Assem-Hafez authored Mar 23, 2024
1 parent 9990475 commit df73ace
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"lodash.camelcase": "^4.3.0",
"lodash.get": "^4.4.2",
"lodash.isequal": "^4.5.0",
"lodash.isstring": "^4.0.1",
"lodash.lowercase": "^4.3.0",
"lodash.snakecase": "^4.1.1",
"lodash.startcase": "^4.4.0",
Expand Down
14 changes: 13 additions & 1 deletion server/router/helpers/build-query-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,32 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const isString = require('lodash.isstring');
const { STATE_TO_FILTER_BY_MAP } = require('../constants');

const getStatusQueryValue = status => {
if (isString(status)) {
return `"${status}"`;
} else if (Number.isInteger(status)) {
return `${status}`;
} // stringify value to convert 0 to none falsy value 0 -> "0"

return '';
};

const buildQueryString = (
startTime,
endTime,
{ isCron, state = 'closed', status, workflowId, workflowName } = {}
) => {
const filterBy = STATE_TO_FILTER_BY_MAP[state];
const statusQueryValue = getStatusQueryValue(status);

return [
`${filterBy} >= "${startTime.toISOString()}"`,
`${filterBy} <= "${endTime.toISOString()}"`,
state === 'open' && `CloseTime = missing`,
status && `CloseStatus = ${status}`,
statusQueryValue && `CloseStatus = ${statusQueryValue}`,
isCron !== undefined && `IsCron = "${isCron}"`,
workflowId && `WorkflowID = "${workflowId}"`,
workflowName && `WorkflowType = "${workflowName}"`,
Expand Down
24 changes: 24 additions & 0 deletions server/router/helpers/build-query-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ describe('buildQueryString', () => {
});

describe('status = "Completed"', () => {
const status = 'Completed';

it('should return "CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = "Completed"".', () => {
const output = buildQueryString(startTime, endTime, { status });

expect(output).toEqual(
'CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = "Completed"'
);
});
});

describe('archival status, status = 0', () => {
const status = 0;

it('should return "CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = 0".', () => {
const output = buildQueryString(startTime, endTime, { status });

expect(output).toEqual(
'CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = 0'
);
});
});

describe('archival status, status = 1', () => {
const status = 1;

it('should return "CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = 1".', () => {
Expand Down

0 comments on commit df73ace

Please sign in to comment.