From ec7de961929a6189f3c924cd3a2d4893db4f54d1 Mon Sep 17 00:00:00 2001 From: hoeppner-dataport Date: Thu, 13 Jun 2024 21:46:00 +0200 Subject: [PATCH] test trackExecutionTimeDecorator --- .../track-execution-time.decorator.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 apps/server/src/modules/board/metrics/track-execution-time.decorator.spec.ts diff --git a/apps/server/src/modules/board/metrics/track-execution-time.decorator.spec.ts b/apps/server/src/modules/board/metrics/track-execution-time.decorator.spec.ts new file mode 100644 index 00000000000..76e3cb98624 --- /dev/null +++ b/apps/server/src/modules/board/metrics/track-execution-time.decorator.spec.ts @@ -0,0 +1,36 @@ +import { TrackExecutionTime } from './track-execution-time.decorator'; + +class MockClassWithTrackingFunction { + trackExecutionTime(methodName: string, executionTime: number) { + console.log(`Executing method ${methodName} took ${executionTime}ms`); + } +} +class MockClassWithoutTrackingFunction { + hello() { + console.log('Hello'); + } +} + +describe('TrackExecutionTimeDecorator', () => { + describe('track', () => { + describe('when a tracking function is defined in the target object', () => { + it('should not throw an exception', () => { + const decorator = TrackExecutionTime(); + + const target = new MockClassWithTrackingFunction(); + expect(() => decorator(target, 'nameOfFunctionBeingTracked', {})).not.toThrow(); + }); + }); + + describe('when no tracking function is defined in the target object', () => { + it('should throw an exception', () => { + const decorator = TrackExecutionTime(); + + const target = new MockClassWithoutTrackingFunction(); + expect(() => decorator(target, 'nameOfFunctionBeingTracked', {})).toThrowError( + `The class MockClassWithoutTrackingFunction does not implement the required trackExecutionTime method.` + ); + }); + }); + }); +});