From 3a9ea1e10207ff8c4d0fa5de9dc899adacee832a Mon Sep 17 00:00:00 2001 From: "Ayobami O. Idowu" Date: Wed, 11 Oct 2023 09:57:46 -0700 Subject: [PATCH] fix: filter out draft submissions on the submission page search --- app/src/forms/form/service.js | 14 +++----------- app/tests/unit/forms/form/service.spec.js | 14 +++++++------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/src/forms/form/service.js b/app/src/forms/form/service.js index 8fcc69e2b..3e026dace 100644 --- a/app/src/forms/form/service.js +++ b/app/src/forms/form/service.js @@ -249,6 +249,7 @@ const service = { .modify('filterCreatedBy', params.createdBy) .modify('filterFormVersionId', params.formVersionId) .modify('filterVersion', params.version) + .modify('filterformSubmissionStatusCode', JSON.parse(params.filterformSubmissionStatusCode)) .modify('orderDefault', params.sortBy && params.page ? true : false, params); if (params.createdAt && Array.isArray(params.createdAt) && params.createdAt.length == 2) { query.modify('filterCreatedAt', params.createdAt[0], params.createdAt[1]); @@ -283,20 +284,12 @@ const service = { ); } if (params.paginationEnabled) { - return await service.processPaginationData( - query, - parseInt(params.page), - parseInt(params.itemsPerPage), - params.filterformSubmissionStatusCode, - params.totalSubmissions, - params.search, - params.searchEnabled - ); + return await service.processPaginationData(query, parseInt(params.page), parseInt(params.itemsPerPage), params.totalSubmissions, params.search, params.searchEnabled); } return query; }, - async processPaginationData(query, page, itemsPerPage, filterformSubmissionStatusCode, totalSubmissions, search, searchEnabled) { + async processPaginationData(query, page, itemsPerPage, totalSubmissions, search, searchEnabled) { let isSearchAble = typeUtils.isBoolean(searchEnabled) ? searchEnabled : searchEnabled !== undefined ? JSON.parse(searchEnabled) : false; if (isSearchAble) { let submissionsData = await query; @@ -338,7 +331,6 @@ const service = { result.results = searchedData.slice(start, end); return result; } else { - await query.modify('filterformSubmissionStatusCode', filterformSubmissionStatusCode); if (itemsPerPage && parseInt(itemsPerPage) === -1) { return await query.page(parseInt(page), parseInt(totalSubmissions || 0)); } else if (itemsPerPage && parseInt(page) >= 0) { diff --git a/app/tests/unit/forms/form/service.spec.js b/app/tests/unit/forms/form/service.spec.js index 17fc0cf98..d7eee486d 100644 --- a/app/tests/unit/forms/form/service.spec.js +++ b/app/tests/unit/forms/form/service.spec.js @@ -417,7 +417,7 @@ describe('processPaginationData', () => { modify: () => jest.fn().mockReturnThis(), }; }); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 10, false, 0, null, false); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 10, 0, null, false); expect(result.results).toHaveLength(10); expect(result.total).toEqual(SubmissionData.length); }); @@ -432,7 +432,7 @@ describe('processPaginationData', () => { modify: () => jest.fn().mockReturnThis(), }; }); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, false, 0, null, false); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, 0, null, false); expect(result.results).toHaveLength(5); expect(result.total).toEqual(SubmissionData.length); }); @@ -447,29 +447,29 @@ describe('processPaginationData', () => { modify: () => jest.fn().mockReturnThis(), }; }); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 1, 5, false, 0, null, false); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 1, 5, 0, null, false); expect(result.results).toHaveLength(5); expect(result.total).toEqual(SubmissionData.length); }); it('search submission data with pagination base on datetime', async () => { MockModel.query.mockImplementation((data) => data); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, false, 0, '2023-08-19T19:11', true); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, 0, '2023-08-19T19:11', true); expect(result.results).toHaveLength(3); expect(result.total).toEqual(3); }); it('search submission data with pagination base on any value (first page)', async () => { MockModel.query.mockImplementation((data) => data); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, false, 0, 'a', true); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 5, 0, 'a', true); expect(result.results).toHaveLength(5); }); it('search submission data with pagination base on any value (second page)', async () => { MockModel.query.mockImplementation((data) => data); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 1, 5, false, 0, 'a', true); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 1, 5, 0, 'a', true); expect(result.results).toHaveLength(5); }); it('search submission data with pagination base on any value (test for case)', async () => { MockModel.query.mockImplementation((data) => data); - let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 10, false, 0, 'A', true); + let result = await service.processPaginationData(MockModel.query(SubmissionData), 0, 10, 0, 'A', true); expect(result.results).toHaveLength(10); }); });