Skip to content

Commit

Permalink
BC-6453 - re-add loggable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergatco committed Jun 13, 2024
1 parent ec9dddd commit 5069818
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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(','),
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -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(','),
},
});
});
});
});

0 comments on commit 5069818

Please sign in to comment.