mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-01-10 10:12:40 +00:00
60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
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);
|
|
});
|
|
});
|