Skip to content

Commit

Permalink
WIP | create tests post.body.params.transform-pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Nov 1, 2023
1 parent 6912a15 commit 6675d4c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

@Injectable()
export class AjaxPostBodyParamsTransformPipe implements PipeTransform {
async transform(value: AjaxPostBodyParams) {
async transform(value: AjaxPostBodyParams): Promise<unknown> {
if (value) {
let transformed: Exclude<AjaxPostBodyParams, undefined>;

Expand Down

0 comments on commit 6675d4c

Please sign in to comment.