From ebffb7c51ea4e78b3da9eaa8a0addca9b963363a Mon Sep 17 00:00:00 2001 From: Arne Gnisa Date: Thu, 9 Nov 2023 14:50:11 +0100 Subject: [PATCH] N21-1374 increase test coverage --- .../hydra/hydra.adapter.spec.ts | 66 +++++++++++-------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/apps/server/src/infra/oauth-provider/hydra/hydra.adapter.spec.ts b/apps/server/src/infra/oauth-provider/hydra/hydra.adapter.spec.ts index 5ab212a5cae..9d2cb8e9a94 100644 --- a/apps/server/src/infra/oauth-provider/hydra/hydra.adapter.spec.ts +++ b/apps/server/src/infra/oauth-provider/hydra/hydra.adapter.spec.ts @@ -138,36 +138,50 @@ describe('HydraService', () => { }); describe('when error occurs', () => { - const setup = () => { - const axiosError: AxiosError = { - isAxiosError: true, - name: 'AxiosError', - message: 'Axios error message', - config: { - headers: {} as AxiosHeaders, - }, - response: { - status: 400, - statusText: 'Bad Request', - headers: {} as AxiosHeaders, - data: { - error: { - message: 'Some error message', - code: 123, - }, + describe('when error is an axios error', () => { + const setup = () => { + const axiosError: AxiosError = { + isAxiosError: true, + name: 'AxiosError', + message: 'Axios error message', + config: { + headers: {} as AxiosHeaders, }, - } as AxiosResponse, - } as AxiosError; + response: { + status: 400, + statusText: 'Bad Request', + headers: {} as AxiosHeaders, + data: { + error: { + message: 'Some error message', + code: 123, + }, + }, + } as AxiosResponse, + } as AxiosError; - httpService.request.mockReturnValue(throwError(() => axiosError)); - }; + httpService.request.mockReturnValueOnce(throwError(() => axiosError)); + }; - it('should throw hydra oauth loggable exception', async () => { - setup(); + it('should throw hydra oauth loggable exception', async () => { + setup(); - await expect(service.listOAuth2Clients()).rejects.toThrow( - new HydraOauthLoggableException(`${hydraUri}/clients`, 'GET', 'Some error message', 123) - ); + await expect(service.listOAuth2Clients()).rejects.toThrow( + new HydraOauthLoggableException(`${hydraUri}/clients`, 'GET', 'Some error message', 123) + ); + }); + }); + + describe('when error is any other error', () => { + const setup = () => { + httpService.request.mockReturnValueOnce(throwError(() => new Error('unknown error'))); + }; + + it('should throw the error', async () => { + setup(); + + await expect(service.listOAuth2Clients()).rejects.toThrow(new Error('unknown error')); + }); }); }); });