-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correction and add test for h5p mapper
- Loading branch information
1 parent
9b58ed7
commit 24f27a5
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
9
apps/server/src/modules/h5p-editor/mapper/h5p-error.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |