Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin-form.service): fixed logical error in duplicate form field #2301

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app/modules/form/admin-form/admin-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,12 @@ export const duplicateFormField = (
},
).andThen((updatedForm) => {
if (!updatedForm) {
return errAsync(new FormNotFoundError())
// Success means field is in initial form object but query still returned null.
// Return best guess error that form is now not found in the DB.
// Otherwise, err(FieldNotFoundError) will be returned by the function.
return getFormField(form, fieldId).asyncAndThen(() =>
seaerchin marked this conversation as resolved.
Show resolved Hide resolved
errAsync(new FormNotFoundError()),
)
}
const updatedField = last(updatedForm.form_fields)
return updatedField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,9 @@ describe('admin-form.form.routes', () => {

// Assert
expect(response.status).toEqual(404)
expect(response.body).toEqual({ message: 'Form not found' })
expect(response.body).toEqual({
message: `Attempted to retrieve field ${randomFieldId} from ${formToUpdate._id} but field was not present`,
})
})

it('should return 410 when form is already archived', async () => {
Expand Down