mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-01-10 10:12:40 +00:00
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { HasRole } from '@modules/ad/interface/grpc-controllers/dtos/validators/decorators/has-role.decorator';
|
|
import { Validator } from 'class-validator';
|
|
|
|
describe('has role decorator', () => {
|
|
class MyClass {
|
|
@HasRole('passenger')
|
|
driver: boolean;
|
|
|
|
passenger: boolean;
|
|
}
|
|
it('should return a property decorator has a function', () => {
|
|
const hasRole = HasRole('property');
|
|
expect(typeof hasRole).toBe('function');
|
|
});
|
|
it('should validate an instance with driver only set to true', async () => {
|
|
const myClassInstance = new MyClass();
|
|
myClassInstance.driver = true;
|
|
myClassInstance.passenger = false;
|
|
const validator = new Validator();
|
|
const validation = await validator.validate(myClassInstance);
|
|
expect(validation.length).toBe(0);
|
|
});
|
|
it('should validate an instance with passenger only set to true', async () => {
|
|
const myClassInstance = new MyClass();
|
|
myClassInstance.driver = false;
|
|
myClassInstance.passenger = true;
|
|
const validator = new Validator();
|
|
const validation = await validator.validate(myClassInstance);
|
|
expect(validation.length).toBe(0);
|
|
});
|
|
it('should validate an instance with driver and passenger set to true', async () => {
|
|
const myClassInstance = new MyClass();
|
|
myClassInstance.driver = true;
|
|
myClassInstance.passenger = true;
|
|
const validator = new Validator();
|
|
const validation = await validator.validate(myClassInstance);
|
|
expect(validation.length).toBe(0);
|
|
});
|
|
it('should not validate an instance without driver and passenger set to true', async () => {
|
|
const myClassInstance = new MyClass();
|
|
myClassInstance.driver = false;
|
|
myClassInstance.passenger = false;
|
|
const validator = new Validator();
|
|
const validation = await validator.validate(myClassInstance);
|
|
expect(validation.length).toBe(1);
|
|
});
|
|
});
|