Skip to content

Commit

Permalink
Remove form level info from payload that creates confirmation id dupl…
Browse files Browse the repository at this point in the history
…ication issue
  • Loading branch information
ptugger committed Aug 31, 2023
1 parent 10a18f7 commit be6f4a3
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
34 changes: 34 additions & 0 deletions app/frontend/src/components/designer/FormViewerMultiUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,40 @@ export default {
});
}
},
popFormLevelInfo(jsonPayload = []) {
/** This function is purely made to remove un-necessery information
* from the json payload of submissions. It will also help to remove crucial data
* to be removed from the payload that should not be going to DB like confirmationId,
* formName,version,createdAt,fullName,username,email,status,assignee,assigneeEmail and
* lateEntry
* Example: Sometime end user use the export json file as a bulk
* upload payload that contains formId, confirmationId and User
* details as well so we need to remove those details from the payload.
*
*/
if (jsonPayload.length) {
jsonPayload.forEach(function (submission) {
delete submission.submit;
delete submission.lateEntry;
const propsToRemove = new Set([
'confirmationId',
'formName',
'version',
'createdAt',
'fullName',
'username',
'email',
'status',
'assignee',
'assigneeEmail',
]);
propsToRemove.forEach((key) => delete submission.form[key]);
});
}
return jsonPayload;
},
async preValidateSubmission() {
try {
if (!Array.isArray(this.Json)) {
Expand Down
39 changes: 39 additions & 0 deletions app/frontend/tests/unit/components/designer/MultiUpload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,43 @@ describe('FormViewerMultiUpload.vue', () => {
expect(notifactionActions.addNotification).not.toHaveBeenCalled();
});
});

describe('popFormLevelInfo', () => {
it('should remove all the form level properties', () => {
const wrapper = shallowMount(FormViewerMultiUpload, {
localVue,
propsData: props,
store,
i18n,
});
const givenArrayOfSubmission = [
{
form: {
confirmationId: '3A31A078',
formName: 'FormTest',
version: 4,
createdAt: '2023-08-31T16:50:33.571Z',
fullName: 'John DOe',
username: 'JOHNDOE',
email: '[email protected]',
status: 'SUBMITTED',
assignee: null,
assigneeEmail: null,
},
lateEntry: false,
simplenumber: 4444,
},
];
const expectedArrayOfSubmission = [
{
form: {},
simplenumber: 4444,
},
];

const response = wrapper.vm.popFormLevelInfo(givenArrayOfSubmission);

expect(response).toEqual(expectedArrayOfSubmission);
});
});
});
25 changes: 24 additions & 1 deletion app/src/forms/form/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ const service = {
let recordsToInsert = [];
let submissionId;
// let's create multiple submissions with same metadata
submissionDataArray.map((singleData) => {
service.popFormLevelInfo(submissionDataArray).map((singleData) => {
submissionId = uuidv4();
recordsToInsert.push({
...recordWithoutData,
Expand Down Expand Up @@ -781,6 +781,29 @@ const service = {
throw err;
}
},
popFormLevelInfo: (jsonPayload = []) => {
/** This function is purely made to remove un-necessery information
* from the json payload of submissions. It will also help to remove crucial data
* to be removed from the payload that should not be going to DB like confirmationId,
* formName,version,createdAt,fullName,username,email,status,assignee,assigneeEmail and
* lateEntry
* Example: Sometime end user use the export json file as a bulk
* upload payload that contains formId, confirmationId and User
* details as well so we need to remove those details from the payload.
*
*/
if (jsonPayload.length) {
jsonPayload.forEach(function (submission) {
delete submission.submit;
delete submission.lateEntry;

const propsToRemove = new Set(['confirmationId', 'formName', 'version', 'createdAt', 'fullName', 'username', 'email', 'status', 'assignee', 'assigneeEmail']);

propsToRemove.forEach((key) => delete submission.form[key]);
});
}
return jsonPayload;
},
};

module.exports = service;
32 changes: 32 additions & 0 deletions app/tests/unit/forms/form/service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,35 @@ describe('readVersionFields', () => {
expect(fields.length).toEqual(1);
});
});

describe('popFormLevelInfo', () => {
it('should remove all the form level properties', () => {
const givenArrayOfSubmission = [
{
form: {
confirmationId: '3A31A078',
formName: 'FormTest',
version: 4,
createdAt: '2023-08-31T16:50:33.571Z',
fullName: 'John DOe',
username: 'JOHNDOE',
email: '[email protected]',
status: 'SUBMITTED',
assignee: null,
assigneeEmail: null,
},
lateEntry: false,
simplenumber: 4444,
},
];
const expectedArrayOfSubmission = [
{
form: {},
simplenumber: 4444,
},
];

const response = service.popFormLevelInfo(givenArrayOfSubmission);
expect(response).toEqual(expectedArrayOfSubmission);
});
});

0 comments on commit be6f4a3

Please sign in to comment.