From 0aa5a912071c152ea73163ff6c2ea45f4d03f959 Mon Sep 17 00:00:00 2001 From: Caspar Neumann Date: Thu, 23 Nov 2023 13:56:05 +0100 Subject: [PATCH] Test for castToLibrariesContentType Error Case --- .../service/h5p-library-management.service.spec.ts | 14 +++++++++++++- .../service/h5p-library-management.service.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.spec.ts b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.spec.ts index 23937527e3f..b12319884f7 100644 --- a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.spec.ts +++ b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.spec.ts @@ -3,8 +3,9 @@ import { createMock } from '@golevelup/ts-jest'; import { ContentStorage, LibraryStorage } from '@src/modules/h5p-editor/service'; import { IHubContentType, ILibraryAdministrationOverviewItem } from '@lumieducation/h5p-server/build/src/types'; import { ConfigService } from '@nestjs/config'; -import { H5PLibraryManagementService } from './h5p-library-management.service'; +import { H5PLibraryManagementService, castToLibrariesContentType } from './h5p-library-management.service'; import { IH5PLibraryManagementConfig } from './h5p-library-management.config'; +import { InternalServerErrorException } from '@nestjs/common'; jest.mock('@lumieducation/h5p-server', () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -240,4 +241,15 @@ describe('H5PLibraryManagementService', () => { }); }); }); + + describe('castToLibrariesContentType', () => { + describe('when castToLibrariesContentType has been called successfully', () => { + it('should throw InternalServerErrorException', () => { + const randomObject = { + random: 1, + }; + expect(() => castToLibrariesContentType(randomObject)).toThrow(InternalServerErrorException); + }); + }); + }); }); diff --git a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts index a63ad7953b2..a6ab56ae29a 100644 --- a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts +++ b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts @@ -38,7 +38,7 @@ function isLibrariesContentType(object: unknown): object is LibrariesContentType return isType; } -const castToLibrariesContentType = (object: unknown): LibrariesContentType => { +export const castToLibrariesContentType = (object: unknown): LibrariesContentType => { if (!isLibrariesContentType(object)) { throw new InternalServerErrorException('Invalid input type for castToLibrariesContentType'); }