mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-01-11 17:32:40 +00:00
move tests folder to the root
This commit is contained in:
59
tests/unit/ad/interface/has-seats.decorator.spec.ts
Normal file
59
tests/unit/ad/interface/has-seats.decorator.spec.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { HasSeats } from '@modules/ad/interface/grpc-controllers/dtos/validators/decorators/has-seats.decorator';
|
||||
import { Validator } from 'class-validator';
|
||||
|
||||
describe('has seats decorator', () => {
|
||||
class MyClass {
|
||||
@HasSeats('seatsProposed')
|
||||
driver: boolean;
|
||||
@HasSeats('seatsRequested')
|
||||
passenger: boolean;
|
||||
|
||||
seatsProposed?: number;
|
||||
seatsRequested?: number;
|
||||
}
|
||||
it('should return a property decorator has a function', () => {
|
||||
const hasSeats = HasSeats('property');
|
||||
expect(typeof hasSeats).toBe('function');
|
||||
});
|
||||
it('should validate an instance with seats proposed as driver', async () => {
|
||||
const myClassInstance = new MyClass();
|
||||
myClassInstance.driver = true;
|
||||
myClassInstance.seatsProposed = 3;
|
||||
const validator = new Validator();
|
||||
const validation = await validator.validate(myClassInstance);
|
||||
expect(validation.length).toBe(0);
|
||||
});
|
||||
it('should validate an instance with seats requested as passenger', async () => {
|
||||
const myClassInstance = new MyClass();
|
||||
myClassInstance.passenger = true;
|
||||
myClassInstance.seatsRequested = 1;
|
||||
const validator = new Validator();
|
||||
const validation = await validator.validate(myClassInstance);
|
||||
expect(validation.length).toBe(0);
|
||||
});
|
||||
it('should validate an instance with seats proposed as driver and passenger', async () => {
|
||||
const myClassInstance = new MyClass();
|
||||
myClassInstance.driver = true;
|
||||
myClassInstance.seatsProposed = 3;
|
||||
myClassInstance.passenger = true;
|
||||
myClassInstance.seatsRequested = 1;
|
||||
const validator = new Validator();
|
||||
const validation = await validator.validate(myClassInstance);
|
||||
expect(validation.length).toBe(0);
|
||||
});
|
||||
it('should not validate an instance without seats proposed as driver', async () => {
|
||||
const myClassInstance = new MyClass();
|
||||
myClassInstance.driver = true;
|
||||
myClassInstance.seatsProposed = 0;
|
||||
const validator = new Validator();
|
||||
const validation = await validator.validate(myClassInstance);
|
||||
expect(validation.length).toBe(1);
|
||||
});
|
||||
it('should not validate an instance without seats requested as passenger', async () => {
|
||||
const myClassInstance = new MyClass();
|
||||
myClassInstance.passenger = true;
|
||||
const validator = new Validator();
|
||||
const validation = await validator.validate(myClassInstance);
|
||||
expect(validation.length).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user