diff --git a/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.spec.ts b/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.spec.ts new file mode 100644 index 00000000000..ab2164c79cb --- /dev/null +++ b/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.spec.ts @@ -0,0 +1,41 @@ +import { AjaxPostBodyParams, LibrariesBodyParams, LibraryParametersBodyParams } from './post.body.params'; +import { AjaxPostBodyParamsTransformPipe } from './post.body.params.transform-pipe'; + +describe('transform', () => { + let ajaxBodyTransformPipe: AjaxPostBodyParamsTransformPipe; + let emptyAjaxPostBodyParams1: AjaxPostBodyParams; + // let emptyAjaxPostBodyParams2: AjaxPostBodyParams; + let emptyAjaxPostBodyParams3: AjaxPostBodyParams; + let emptyAjaxPostBodyParams4: AjaxPostBodyParams; + + beforeAll(() => { + ajaxBodyTransformPipe = new AjaxPostBodyParamsTransformPipe(); + + const emptyLibrariesBodyParams: LibrariesBodyParams = { + libraries: [], + }; + + const emptyLibraryParametersBodyParams: LibraryParametersBodyParams = { + libraryParameters: '', + }; + + emptyAjaxPostBodyParams1 = emptyLibrariesBodyParams; + emptyAjaxPostBodyParams3 = emptyLibraryParametersBodyParams; + emptyAjaxPostBodyParams4 = undefined; + }); + + it('when libaries in value', async () => { + const result = await ajaxBodyTransformPipe.transform(emptyAjaxPostBodyParams1); + expect(result).toBeDefined(); + }); + + it('when libaryParameters in value', async () => { + const result = await ajaxBodyTransformPipe.transform(emptyAjaxPostBodyParams3); + expect(result).toBeDefined(); + }); + + it('when not libaries | contentId | libaryParameters in value', async () => { + const result = await ajaxBodyTransformPipe.transform(emptyAjaxPostBodyParams4); + expect(result).toBeUndefined(); + }); +}); diff --git a/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.ts b/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.ts index 40f7348cb97..f37d3e02f1a 100644 --- a/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.ts +++ b/apps/server/src/modules/h5p-editor/controller/dto/ajax/post.body.params.transform-pipe.ts @@ -15,7 +15,7 @@ import { @Injectable() export class AjaxPostBodyParamsTransformPipe implements PipeTransform { - async transform(value: AjaxPostBodyParams) { + async transform(value: AjaxPostBodyParams): Promise { if (value) { let transformed: Exclude;