Skip to content

Commit

Permalink
correction and add test for h5p mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
MajedAlaitwniCap committed Nov 1, 2023
1 parent 9b58ed7 commit 24f27a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
26 changes: 26 additions & 0 deletions apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { H5pError } from '@lumieducation/h5p-server';
import { HttpException, InternalServerErrorException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { H5PErrorMapper } from './h5p-error.mapper';

describe('H5PErrorMapper', () => {
let h5pErrorMapper: H5PErrorMapper;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
providers: [H5PErrorMapper],
}).compile();

h5pErrorMapper = app.get<H5PErrorMapper>(H5PErrorMapper);
});

describe('mapH5pError', () => {
it('should map H5pError to HttpException', () => {
const error = new H5pError('h5p error massage');
const result = h5pErrorMapper.mapH5pError(error);

expect(result).toBeInstanceOf(HttpException);
expect(result.message).toEqual('h5p error massage');
});
});
});
9 changes: 2 additions & 7 deletions apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { H5pError } from '@lumieducation/h5p-server';
import { HttpException, InternalServerErrorException } from '@nestjs/common';
import { HttpException } from '@nestjs/common';

export class H5PErrorMapper {
public mapH5pError(error: H5pError) {
if (error instanceof H5pError) {
return new HttpException(error.message, error.httpStatusCode);
}
return new HttpException('message', 500, {
cause: new InternalServerErrorException({ error }),
});
return new HttpException(error.message, error.httpStatusCode);
}
}

0 comments on commit 24f27a5

Please sign in to comment.