Skip to content

Commit

Permalink
test: Add test cases for each pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdlrahmanSaberAbdo committed Jun 25, 2023
1 parent adc3a9c commit 37bae99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/common/test/pipes/parse-bool.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ describe('ParseBoolPipe', () => {
expect(await target.transform(false, {} as ArgumentMetadata)).to.be
.false;
});

it('should not throw an error if the value is undefined/null and optional is true', async () => {
const target = new ParseBoolPipe({ optional: true });
const value = await target.transform(undefined, {} as ArgumentMetadata);
expect(value).to.equal(undefined);
});
});
describe('when validation fails', () => {
it('should throw an error', async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/test/pipes/parse-float.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe('ParseFloatPipe', () => {
parseFloat(num),
);
});
it('should not throw an error if the value is undefined/null and optional is true', async () => {
const target = new ParseFloatPipe({ optional: true });
const value = await target.transform(undefined, {} as ArgumentMetadata);
expect(value).to.equal(undefined);
});
});
describe('when validation fails', () => {
it('should throw an error', async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/test/pipes/parse-int.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('ParseIntPipe', () => {
-3,
);
});
it('should not throw an error if the value is undefined/null and optional is true', async () => {
const target = new ParseIntPipe({ optional: true });
const value = await target.transform(undefined, {} as ArgumentMetadata);
expect(value).to.equal(undefined);
});
});
describe('when validation fails', () => {
it('should throw an error', async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/test/pipes/parse-uuid.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ describe('ParseUUIDPipe', () => {
target = new ParseUUIDPipe({ version: '5', exceptionFactory });
expect(await target.transform(v5, {} as ArgumentMetadata)).to.equal(v5);
});
it('should not throw an error if the value is undefined/null and optional is true', async () => {
const target = new ParseUUIDPipe({ optional: true });
const value = await target.transform(undefined, {} as ArgumentMetadata);
expect(value).to.equal(undefined);
});
});

describe('when validation fails', () => {
Expand Down

0 comments on commit 37bae99

Please sign in to comment.