Skip to content

Commit

Permalink
fix(admin-form.service): fixed logical error in duplicate form field (#…
Browse files Browse the repository at this point in the history
…2301)

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

* docs(admin-form.service): updated comments for duplicateFormField
  • Loading branch information
seaerchin authored Jul 7, 2021
1 parent bc9b913 commit 01ede7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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(() =>
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

0 comments on commit 01ede7a

Please sign in to comment.