Skip to content

Commit df73ace

Browse files
authored
fix status in query string to accept strings and numbers (#542)
* 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
1 parent 9990475 commit df73ace

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"lodash.camelcase": "^4.3.0",
7070
"lodash.get": "^4.4.2",
7171
"lodash.isequal": "^4.5.0",
72+
"lodash.isstring": "^4.0.1",
7273
"lodash.lowercase": "^4.3.0",
7374
"lodash.snakecase": "^4.1.1",
7475
"lodash.startcase": "^4.4.0",

server/router/helpers/build-query-string.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

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

25+
const getStatusQueryValue = status => {
26+
if (isString(status)) {
27+
return `"${status}"`;
28+
} else if (Number.isInteger(status)) {
29+
return `${status}`;
30+
} // stringify value to convert 0 to none falsy value 0 -> "0"
31+
32+
return '';
33+
};
34+
2435
const buildQueryString = (
2536
startTime,
2637
endTime,
2738
{ isCron, state = 'closed', status, workflowId, workflowName } = {}
2839
) => {
2940
const filterBy = STATE_TO_FILTER_BY_MAP[state];
41+
const statusQueryValue = getStatusQueryValue(status);
3042

3143
return [
3244
`${filterBy} >= "${startTime.toISOString()}"`,
3345
`${filterBy} <= "${endTime.toISOString()}"`,
3446
state === 'open' && `CloseTime = missing`,
35-
status && `CloseStatus = ${status}`,
47+
statusQueryValue && `CloseStatus = ${statusQueryValue}`,
3648
isCron !== undefined && `IsCron = "${isCron}"`,
3749
workflowId && `WorkflowID = "${workflowId}"`,
3850
workflowName && `WorkflowType = "${workflowName}"`,

server/router/helpers/build-query-string.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ describe('buildQueryString', () => {
101101
});
102102

103103
describe('status = "Completed"', () => {
104+
const status = 'Completed';
105+
106+
it('should return "CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = "Completed"".', () => {
107+
const output = buildQueryString(startTime, endTime, { status });
108+
109+
expect(output).toEqual(
110+
'CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = "Completed"'
111+
);
112+
});
113+
});
114+
115+
describe('archival status, status = 0', () => {
116+
const status = 0;
117+
118+
it('should return "CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = 0".', () => {
119+
const output = buildQueryString(startTime, endTime, { status });
120+
121+
expect(output).toEqual(
122+
'CloseTime >= "2021-06-03T00:00:00.000Z" and CloseTime <= "2021-06-04T00:00:00.000Z" and CloseStatus = 0'
123+
);
124+
});
125+
});
126+
127+
describe('archival status, status = 1', () => {
104128
const status = 1;
105129

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

0 commit comments

Comments
 (0)