From 4555583cb3d644fc001812dc94a12841a19847c0 Mon Sep 17 00:00:00 2001 From: LinHuiqing Date: Wed, 20 Sep 2023 11:16:31 +0800 Subject: [PATCH] fix: broken receiver tests due to answer field --- .../__tests__/receiver.service.spec.ts | 25 ++++++++----------- .../receiver/__tests__/receiver.utils.spec.ts | 13 ---------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/app/modules/submission/receiver/__tests__/receiver.service.spec.ts b/src/app/modules/submission/receiver/__tests__/receiver.service.spec.ts index fa55254185..592bdfe7d8 100644 --- a/src/app/modules/submission/receiver/__tests__/receiver.service.spec.ts +++ b/src/app/modules/submission/receiver/__tests__/receiver.service.spec.ts @@ -192,14 +192,13 @@ describe('receiver.service', () => { const result = await resultPromise expect(result._unsafeUnwrap()).toEqual({ responses: [ - { + expect.objectContaining({ _id: mockResponse._id, question: mockResponse.question, - answer: VALID_UTF8_FILENAME, fieldType: mockResponse.fieldType, filename: VALID_UTF8_FILENAME, content: Buffer.concat([VALID_UTF8_FILE_CONTENT]), - }, + }), ], }) }) @@ -235,14 +234,13 @@ describe('receiver.service', () => { const result = await resultPromise expect(result._unsafeUnwrap()).toEqual({ responses: [ - { + expect.objectContaining({ _id: mockResponse._id, question: mockResponse.question, - answer: VALID_FILENAME_1, fieldType: mockResponse.fieldType, filename: VALID_FILENAME_1, content: Buffer.concat([VALID_FILE_CONTENT_1]), - }, + }), ], }) }) @@ -282,14 +280,13 @@ describe('receiver.service', () => { const result = await resultPromise expect(result._unsafeUnwrap()).toEqual({ responses: [ - { + expect.objectContaining({ _id: mockAttachment._id, question: mockAttachment.question, - answer: VALID_FILENAME_1, fieldType: mockAttachment.fieldType, filename: VALID_FILENAME_1, content: Buffer.concat([VALID_FILE_CONTENT_1]), - }, + }), { _id: mockTextField._id, question: mockTextField.question, @@ -410,22 +407,20 @@ describe('receiver.service', () => { const result = await resultPromise expect(result._unsafeUnwrap()).toEqual({ responses: [ - { + expect.objectContaining({ _id: mockResponse1._id, question: mockResponse1.question, - answer: `1-${VALID_FILENAME_1}`, fieldType: mockResponse1.fieldType, filename: `1-${VALID_FILENAME_1}`, content: Buffer.concat([VALID_FILE_CONTENT_1]), - }, - { + }), + expect.objectContaining({ _id: mockResponse2._id, question: mockResponse2.question, - answer: VALID_FILENAME_1, fieldType: mockResponse2.fieldType, filename: VALID_FILENAME_1, content: Buffer.concat([VALID_FILE_CONTENT_1]), - }, + }), ], }) }) diff --git a/src/app/modules/submission/receiver/__tests__/receiver.utils.spec.ts b/src/app/modules/submission/receiver/__tests__/receiver.utils.spec.ts index 008b0dcde6..06e705775f 100644 --- a/src/app/modules/submission/receiver/__tests__/receiver.utils.spec.ts +++ b/src/app/modules/submission/receiver/__tests__/receiver.utils.spec.ts @@ -64,19 +64,6 @@ describe('email-submission.util', () => { ).toEqual(secondAttachment.content) }) - it('should overwrite answer with filename when they are different', () => { - const attachment = validSingleFile - const response = getResponse(attachment.fieldId, MOCK_ANSWER) - addAttachmentToResponses([response], [attachment]) - expect(response.answer).toBe(attachment.filename) - expect((response as unknown as IAttachmentResponse).filename).toBe( - attachment.filename, - ) - expect((response as unknown as IAttachmentResponse).content).toEqual( - attachment.content, - ) - }) - it('should do nothing when responses are empty', () => { const responses: FieldResponse[] = [] addAttachmentToResponses(responses, [validSingleFile])