From 50698182dfb7abbfbf5040f39c26b19c843fd0fd Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Thu, 13 Jun 2024 13:13:09 +0200 Subject: [PATCH] BC-6453 - re-add loggable tests --- ...orization-error.loggable-exception.spec.ts | 45 +++++++++++++++++++ ...ation-forbidden.loggable-exception.spec.ts | 41 +++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 apps/server/src/infra/authorization-client/error/authorization-error.loggable-exception.spec.ts create mode 100644 apps/server/src/infra/authorization-client/error/authorization-forbidden.loggable-exception.spec.ts diff --git a/apps/server/src/infra/authorization-client/error/authorization-error.loggable-exception.spec.ts b/apps/server/src/infra/authorization-client/error/authorization-error.loggable-exception.spec.ts new file mode 100644 index 00000000000..40831a5212a --- /dev/null +++ b/apps/server/src/infra/authorization-client/error/authorization-error.loggable-exception.spec.ts @@ -0,0 +1,45 @@ +import { Action, AuthorizationBodyParamsReferenceType } from '../authorization-api-client'; +import { AuthorizationErrorLoggableException } from './authorization-error.loggable-exception'; + +describe('AuthorizationErrorLoggableException', () => { + describe('getLogMessage', () => { + const setup = () => { + const error = new Error('testError'); + + const params = { + context: { + action: Action.READ, + requiredPermissions: [], + }, + referenceType: AuthorizationBodyParamsReferenceType.COURSES, + referenceId: 'someReferenceId', + }; + + const exception = new AuthorizationErrorLoggableException(error, params); + + return { + error, + exception, + params, + }; + }; + + it('should log the correct message', () => { + const { error, exception, params } = setup(); + + const result = exception.getLogMessage(); + + expect(result).toEqual({ + type: 'INTERNAL_SERVER_ERROR', + error, + stack: expect.any(String), + data: { + action: params.context.action, + referenceId: params.referenceId, + referenceType: params.referenceType, + requiredPermissions: params.context.requiredPermissions.join(','), + }, + }); + }); + }); +}); diff --git a/apps/server/src/infra/authorization-client/error/authorization-forbidden.loggable-exception.spec.ts b/apps/server/src/infra/authorization-client/error/authorization-forbidden.loggable-exception.spec.ts new file mode 100644 index 00000000000..75b19806969 --- /dev/null +++ b/apps/server/src/infra/authorization-client/error/authorization-forbidden.loggable-exception.spec.ts @@ -0,0 +1,41 @@ +import { AuthorizationForbiddenLoggableException } from './authorization-forbidden.loggable-exception'; +import { Action, AuthorizationBodyParamsReferenceType } from '../authorization-api-client'; + +describe('AuthorizationForbiddenLoggableException', () => { + describe('getLogMessage', () => { + const setup = () => { + const params = { + context: { + action: Action.READ, + requiredPermissions: [], + }, + referenceType: AuthorizationBodyParamsReferenceType.COURSES, + referenceId: 'someReferenceId', + }; + + const exception = new AuthorizationForbiddenLoggableException(params); + + return { + exception, + params, + }; + }; + + it('should log the correct message', () => { + const { exception, params } = setup(); + + const result = exception.getLogMessage(); + + expect(result).toEqual({ + type: 'FORBIDDEN_EXCEPTION', + stack: expect.any(String), + data: { + action: params.context.action, + referenceId: params.referenceId, + referenceType: params.referenceType, + requiredPermissions: params.context.requiredPermissions.join(','), + }, + }); + }); + }); +});