From a5180aec0c35d8d33171a5772cad4d582773e8c3 Mon Sep 17 00:00:00 2001 From: Bartosz Nowicki <116367402+bn-pass@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:03:06 +0100 Subject: [PATCH] add more test cases to the deletion client unit tests --- .../deletion/client/deletion.client.spec.ts | 74 ++++++++++++++----- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/deletion/client/deletion.client.spec.ts b/apps/server/src/modules/deletion/client/deletion.client.spec.ts index ae83ad71f7d..eeebd688b21 100644 --- a/apps/server/src/modules/deletion/client/deletion.client.spec.ts +++ b/apps/server/src/modules/deletion/client/deletion.client.spec.ts @@ -5,6 +5,7 @@ import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { axiosResponseFactory } from '@shared/testing'; +import { DeletionRequestInputBuilder, DeletionRequestOutputBuilder } from '@modules/deletion'; import { DeletionRequestOutput } from './interface'; import { DeletionClient } from './deletion.client'; @@ -52,17 +53,12 @@ describe(DeletionClient.name, () => { describe('queueDeletionRequest', () => { describe('when received valid response with expected HTTP status code', () => { const setup = () => { - const input = { - targetRef: { - domain: 'user', - id: '652f1625e9bc1a13bdaae48b', - }, - }; + const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b'); - const output: DeletionRequestOutput = { - requestId: '6536ce29b595d7c8e5faf200', - deletionPlannedAt: new Date('2024-10-15T12:42:50.521Z'), - }; + const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build( + '6536ce29b595d7c8e5faf200', + new Date('2024-10-15T12:42:50.521Z') + ); const response: AxiosResponse = axiosResponseFactory.build({ data: output, @@ -85,14 +81,9 @@ describe(DeletionClient.name, () => { describe('when received invalid HTTP status code in a response', () => { const setup = () => { - const input = { - targetRef: { - domain: 'user', - id: '652f1625e9bc1a13bdaae48b', - }, - }; + const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b'); - const output: DeletionRequestOutput = { requestId: '', deletionPlannedAt: new Date() }; + const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build('', new Date()); const response: AxiosResponse = axiosResponseFactory.build({ data: output, @@ -110,5 +101,54 @@ describe(DeletionClient.name, () => { await expect(client.queueDeletionRequest(input)).rejects.toThrow(Error); }); }); + + describe('when received no requestId in a response', () => { + const setup = () => { + const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b'); + + const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build( + '', + new Date('2024-10-15T12:42:50.521Z') + ); + + const response: AxiosResponse = axiosResponseFactory.build({ + data: output, + status: 202, + }); + + httpService.post.mockReturnValueOnce(of(response)); + + return { input }; + }; + + it('should throw an exception', async () => { + const { input } = setup(); + + await expect(client.queueDeletionRequest(input)).rejects.toThrow(Error); + }); + }); + + describe('when received no deletionPlannedAt in a response', () => { + const setup = () => { + const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b'); + + const response: AxiosResponse = axiosResponseFactory.build({ + data: { + requestId: '6536ce29b595d7c8e5faf200', + }, + status: 202, + }); + + httpService.post.mockReturnValueOnce(of(response)); + + return { input }; + }; + + it('should throw an exception', async () => { + const { input } = setup(); + + await expect(client.queueDeletionRequest(input)).rejects.toThrow(Error); + }); + }); }); });