diff --git a/package.json b/package.json index e3bd4ff5f..aa861b6ef 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/router/helpers/build-query-string.js b/server/router/helpers/build-query-string.js index dd06acf51..fc3888275 100644 --- a/server/router/helpers/build-query-string.js +++ b/server/router/helpers/build-query-string.js @@ -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}"`, diff --git a/server/router/helpers/build-query-string.spec.js b/server/router/helpers/build-query-string.spec.js index 923e3f742..f4657df12 100644 --- a/server/router/helpers/build-query-string.spec.js +++ b/server/router/helpers/build-query-string.spec.js @@ -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".', () => {