Skip to content

Commit

Permalink
test(common): add tests for validation pipe on 'custom' types
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 12, 2024
1 parent d0f401a commit 78b3f0c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/common/test/pipes/validation.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,56 @@ describe('ValidationPipe', () => {
});
});

describe('option: "validateCustomDecorators" when metadata.type is not `body`', () => {
describe('when is set to `true`', () => {
it('should transform and validate', async () => {
const target = new ValidationPipe({
validateCustomDecorators: true,
});

const metadata: ArgumentMetadata = {
type: 'custom',
metatype: TestModel,
data: '',
};

const testObj = { prop1: 'value1', prop2: 'value2' };
expect(await target.transform(testObj, metadata)).to.not.be.undefined;
});
});
describe('when is set to `false`', () => {
it('should throw an error', async () => {
const target = new ValidationPipe({
validateCustomDecorators: false,
});

const metadata: ArgumentMetadata = {
type: 'custom',
metatype: TestModel,
data: '',
};

const objNotFollowingTestModel = { prop1: undefined, prop2: 'value2' };
expect(await target.transform(objNotFollowingTestModel, metadata)).to
.not.be.undefined;
});
});
describe('when is not supplied', () => {
it('should transform and validate', async () => {
const target = new ValidationPipe({});

const metadata: ArgumentMetadata = {
type: 'custom',
metatype: TestModel,
data: '',
};

const testObj = { prop1: 'value1', prop2: 'value2' };
expect(await target.transform(testObj, metadata)).to.not.be.undefined;
});
});
});

describe('option: "errorHttpStatusCode"', () => {
describe('when validation fails', () => {
beforeEach(() => {
Expand Down

0 comments on commit 78b3f0c

Please sign in to comment.