Skip to content

Commit

Permalink
fix: filter out draft submissions on the submission page search
Browse files Browse the repository at this point in the history
  • Loading branch information
timisenco2015 authored Oct 11, 2023
1 parent dd92892 commit 3a9ea1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
14 changes: 3 additions & 11 deletions app/src/forms/form/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions app/tests/unit/forms/form/service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
});
Expand Down

0 comments on commit 3a9ea1e

Please sign in to comment.