diff --git a/src/app/models/form.server.model.ts b/src/app/models/form.server.model.ts index bbe914185c..187e7c15a5 100644 --- a/src/app/models/form.server.model.ts +++ b/src/app/models/form.server.model.ts @@ -685,11 +685,11 @@ const compileFormModel = (db: Mongoose): IFormModel => { FormSchema.statics.createFormLogic = async function ( this: IFormModel, formId: string, - createdLogic: LogicDto, + createLogicBody: LogicDto, ): Promise { return this.findByIdAndUpdate( formId, - { $push: { form_logics: createdLogic } }, + { $push: { form_logics: createLogicBody } }, { new: true, runValidators: true, diff --git a/src/app/modules/form/admin-form/__tests__/admin-form.controller.spec.ts b/src/app/modules/form/admin-form/__tests__/admin-form.controller.spec.ts index 7831f2098d..74ba19b88a 100644 --- a/src/app/modules/form/admin-form/__tests__/admin-form.controller.spec.ts +++ b/src/app/modules/form/admin-form/__tests__/admin-form.controller.spec.ts @@ -7842,7 +7842,7 @@ describe('admin-form.controller', () => { ], } - const mockCreatedLogic = { + const mockCreateLogicBody = { _id: logicId, } as ILogicSchema @@ -7863,7 +7863,7 @@ describe('admin-form.controller', () => { _id: MOCK_USER_ID, }, }, - body: mockCreatedLogic, + body: mockCreateLogicBody, }) const mockRes = expressHandler.mockResponse() @@ -7873,7 +7873,7 @@ describe('admin-form.controller', () => { okAsync(MOCK_FORM), ) MockAdminFormService.createFormLogic.mockReturnValue( - okAsync(mockCreatedLogic), + okAsync(mockCreateLogicBody), ) }) @@ -7892,11 +7892,11 @@ describe('admin-form.controller', () => { ) expect(MockAdminFormService.createFormLogic).toHaveBeenCalledWith( MOCK_FORM, - mockCreatedLogic, + mockCreateLogicBody, ) expect(mockRes.status).toHaveBeenCalledWith(200) - expect(mockRes.json).toHaveBeenCalledWith(mockCreatedLogic) + expect(mockRes.json).toHaveBeenCalledWith(mockCreateLogicBody) }) it('should return 403 when user does not have permissions to update logic', async () => { diff --git a/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts b/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts index ecc28e0bcb..d873e71e08 100644 --- a/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts +++ b/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts @@ -1629,7 +1629,7 @@ describe('admin-form.service', () => { ], } - const createdLogic = { + const createLogicBody = { logicType: LogicType.PreventSubmit, } as ILogicSchema @@ -1685,15 +1685,18 @@ describe('admin-form.service', () => { CREATE_SPY.mockResolvedValue(mockEmailFormUpdated as IFormSchema) // Act - const actualResult = await createFormLogic(mockEmailForm, createdLogic) + const actualResult = await createFormLogic(mockEmailForm, createLogicBody) // Assert expect(actualResult.isOk()).toEqual(true) expect(actualResult._unsafeUnwrap()).toEqual( - expect.objectContaining(createdLogic), + expect.objectContaining(createLogicBody), ) - expect(CREATE_SPY).toHaveBeenCalledWith(mockEmailForm._id, createdLogic) + expect(CREATE_SPY).toHaveBeenCalledWith( + mockEmailForm._id, + createLogicBody, + ) }) it('should return ok(created logic) on successful form logic create for encrypt mode form', async () => { @@ -1701,15 +1704,21 @@ describe('admin-form.service', () => { CREATE_SPY.mockResolvedValue(mockEncryptFormUpdated as IFormSchema) // Act - const actualResult = await createFormLogic(mockEncryptForm, createdLogic) + const actualResult = await createFormLogic( + mockEncryptForm, + createLogicBody, + ) // Assert expect(actualResult.isOk()).toEqual(true) expect(actualResult._unsafeUnwrap()).toEqual( - expect.objectContaining(createdLogic), + expect.objectContaining(createLogicBody), ) - expect(CREATE_SPY).toHaveBeenCalledWith(mockEncryptFormId, createdLogic) + expect(CREATE_SPY).toHaveBeenCalledWith( + mockEncryptFormId, + createLogicBody, + ) }) it('should return err(FormNotFoundError) if db does not return form object', async () => { @@ -1717,13 +1726,19 @@ describe('admin-form.service', () => { CREATE_SPY.mockResolvedValue((undefined as unknown) as IFormSchema) // Act - const actualResult = await createFormLogic(mockEncryptForm, createdLogic) + const actualResult = await createFormLogic( + mockEncryptForm, + createLogicBody, + ) // Assert expect(actualResult.isErr()).toEqual(true) expect(actualResult._unsafeUnwrapErr()).toEqual(new FormNotFoundError()) - expect(CREATE_SPY).toHaveBeenCalledWith(mockEncryptFormId, createdLogic) + expect(CREATE_SPY).toHaveBeenCalledWith( + mockEncryptFormId, + createLogicBody, + ) }) it('should return err(DatabaseError) if db returns form object that does not have form_logics array', async () => { @@ -1735,13 +1750,19 @@ describe('admin-form.service', () => { CREATE_SPY.mockResolvedValue(updatedFormWithoutLogic as IFormSchema) // Act - const actualResult = await createFormLogic(mockEncryptForm, createdLogic) + const actualResult = await createFormLogic( + mockEncryptForm, + createLogicBody, + ) // Assert expect(actualResult.isErr()).toEqual(true) expect(actualResult._unsafeUnwrapErr()).toEqual(new DatabaseError()) - expect(CREATE_SPY).toHaveBeenCalledWith(mockEncryptFormId, createdLogic) + expect(CREATE_SPY).toHaveBeenCalledWith( + mockEncryptFormId, + createLogicBody, + ) }) it('should return err(DatabaseError) if db returns form object that has empty form_logics array', async () => { @@ -1753,13 +1774,19 @@ describe('admin-form.service', () => { CREATE_SPY.mockResolvedValue(updatedFormWithEmptyLogic as IFormSchema) // Act - const actualResult = await createFormLogic(mockEncryptForm, createdLogic) + const actualResult = await createFormLogic( + mockEncryptForm, + createLogicBody, + ) // Assert expect(actualResult.isErr()).toEqual(true) expect(actualResult._unsafeUnwrapErr()).toEqual(new DatabaseError()) - expect(CREATE_SPY).toHaveBeenCalledWith(mockEncryptFormId, createdLogic) + expect(CREATE_SPY).toHaveBeenCalledWith( + mockEncryptFormId, + createLogicBody, + ) }) }) diff --git a/src/app/modules/form/admin-form/admin-form.controller.ts b/src/app/modules/form/admin-form/admin-form.controller.ts index 2263f23268..61b0427b18 100644 --- a/src/app/modules/form/admin-form/admin-form.controller.ts +++ b/src/app/modules/form/admin-form/admin-form.controller.ts @@ -1660,7 +1660,7 @@ export const _handleCreateLogic: RequestHandler< LogicDto > = (req, res) => { const { formId } = req.params - const createdLogic = req.body + const createLogicBody = req.body const sessionUserId = (req.session as Express.AuthedSession).user._id // Step 1: Retrieve currently logged in user. @@ -1676,7 +1676,7 @@ export const _handleCreateLogic: RequestHandler< ) // Step 3: Create form logic .andThen((retrievedForm) => - AdminFormService.createFormLogic(retrievedForm, createdLogic), + AdminFormService.createFormLogic(retrievedForm, createLogicBody), ) .map((createdLogic) => res.status(StatusCodes.OK).json(createdLogic)) .mapErr((error) => { @@ -1687,7 +1687,7 @@ export const _handleCreateLogic: RequestHandler< ...createReqMeta(req), userId: sessionUserId, formId, - createdLogic, + createLogicBody, }, error, }) diff --git a/src/app/modules/form/admin-form/admin-form.service.ts b/src/app/modules/form/admin-form/admin-form.service.ts index 456d12f7eb..5242d5f91f 100644 --- a/src/app/modules/form/admin-form/admin-form.service.ts +++ b/src/app/modules/form/admin-form/admin-form.service.ts @@ -720,24 +720,24 @@ export const updateFormSettings = ( /** * Creates form logic. * @param form The original form to create logic in - * @param createdLogic Object containing the created logic + * @param createLogicBody Object containing the created logic * @returns ok(created logic dto) on success * @returns err(database errors) if db error is thrown during logic update */ export const createFormLogic = ( form: IPopulatedForm, - createdLogic: LogicDto, + createLogicBody: LogicDto, ): ResultAsync => { // Create new form logic return ResultAsync.fromPromise( - FormModel.createFormLogic(form._id, createdLogic), + FormModel.createFormLogic(form._id, createLogicBody), (error) => { logger.error({ message: 'Error occurred when creating form logic', meta: { action: 'createFormLogic', formId: form._id, - createdLogic, + createLogicBody, }, error, }) diff --git a/src/public/services/AdminFormService.ts b/src/public/services/AdminFormService.ts index d8582ee15d..57b71a3022 100644 --- a/src/public/services/AdminFormService.ts +++ b/src/public/services/AdminFormService.ts @@ -124,10 +124,10 @@ export const updateFormEndPage = async ( export const createFormLogic = async ( formId: string, - createdLogic: LogicDto, + createLogicBody: LogicDto, ): Promise => { return axios - .post(`${ADMIN_FORM_ENDPOINT}/${formId}/logic`, createdLogic) + .post(`${ADMIN_FORM_ENDPOINT}/${formId}/logic`, createLogicBody) .then(({ data }) => data) } diff --git a/src/types/form.ts b/src/types/form.ts index 59655a4c71..3dadbc1a56 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -303,7 +303,7 @@ export interface IFormModel extends Model { ): Promise createFormLogic( formId: string, - createdLogic: LogicDto, + createLogicBody: LogicDto, ): Promise deleteFormLogic(formId: string, logicId: string): Promise /**