From cad8d9cb98e70fa470702311002cad20f37b4a4d Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 5 Apr 2024 11:21:36 +0800 Subject: [PATCH] test: add test cases for mrf webhook blocks --- .../__tests__/admin-form.service.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) 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 2d78ff912f..2572faad4b 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 @@ -20,6 +20,7 @@ import { DatabaseError, DatabasePayloadSizeError, DatabaseValidationError, + MalformedParametersError, } from 'src/app/modules/core/core.errors' import { MissingUserError } from 'src/app/modules/user/user.errors' import * as UserService from 'src/app/modules/user/user.service' @@ -1419,6 +1420,47 @@ describe('admin-form.service', () => { ) expect(MOCK_UPDATED_FORM.getSettings).toHaveBeenCalledTimes(0) }) + + it('should not allow webhooks updates for MRF', async () => { + const MOCK_MULTIRESPONDENT_FORM = jest.mocked({ + _id: new ObjectId(), + status: FormStatus.Public, + responseMode: FormResponseMode.Multirespondent, + } as unknown as IPopulatedForm) + const settingsToUpdate: SettingsUpdateDto = { + webhook: { + url: 'does not matter', + }, + } + + // Act + const actualResult = await AdminFormService.updateFormSettings( + MOCK_MULTIRESPONDENT_FORM, + settingsToUpdate, + ) + + // Assert + expect(actualResult._unsafeUnwrapErr()).toBeInstanceOf( + MalformedParametersError, + ) + }) + + it('should allow webhooks updates for encrypt form', async () => { + const settingsToUpdate: SettingsUpdateDto = { + webhook: { + url: 'does not matter', + }, + } + + // Act + const actualResult = await AdminFormService.updateFormSettings( + MOCK_ENCRYPT_FORM, + settingsToUpdate, + ) + + // Assert + expect(actualResult.isOk()).toBeTrue() + }) }) describe('updateFormField', () => {