Skip to content

Commit

Permalink
Test for castToLibrariesContentType Error Case
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Nov 23, 2023
1 parent 83d4300 commit 0aa5a91
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 8 in apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

`@nestjs/common` import should occur before import of `./h5p-library-management.service`

jest.mock('@lumieducation/h5p-server', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand Down Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 0aa5a91

Please sign in to comment.