Skip to content

Commit

Permalink
EW-644 deleted integration test & modfied unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fshmit committed Nov 21, 2023
1 parent a2ac98a commit 8769bab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
36 changes: 0 additions & 36 deletions src/shared/validation/global-validation.pipe.integration-spec.ts

This file was deleted.

50 changes: 46 additions & 4 deletions src/shared/validation/global-validation.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
import { Test, TestingModule } from '@nestjs/testing';
import { GlobalValidationPipe } from './global-validation.pipe.js';
import { DetailedValidationError } from './detailed-validation.error.js';
import { ValidationError } from 'class-validator';

describe('GlobalValidationPipe', () => {
describe('constructor', () => {
it('should instantiate type', () => {
expect(new GlobalValidationPipe()).toBeInstanceOf(GlobalValidationPipe);
});
let module: TestingModule;
let sut: GlobalValidationPipe;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [GlobalValidationPipe],
}).compile();
sut = module.get(GlobalValidationPipe);
});

afterAll(async () => {
await module.close();
});

it('should be defined', () => {
expect(sut).toBeDefined();
});

it('should be instance of ValidationPipe', async () => {
const validationError: ValidationError = {
property: '',
};
await sut
.transform(validationError, {
type: 'body',
metatype: DetailedValidationError,
})
.catch((error: ValidationError) => {
expect(error).toBeInstanceOf(DetailedValidationError);
});
});

it('should throw DetailedValidation error on failure', async () => {
const validationError: ValidationError = {
property: '',
};

await expect(
sut.transform(validationError, {
type: 'body',
metatype: DetailedValidationError,
}),
).rejects.toThrow(DetailedValidationError);
});
});

0 comments on commit 8769bab

Please sign in to comment.