import { validateDto } from '@fc/common' ; import { validationOptions } from '@fc/config' ; import { LoggerLevelNames } from '../enum' ; import { LoggerConfig } from './logger-config.dto' ; describe ( 'LoggerConfig' , ( ) => { const correctObjectMock = { level : LoggerLevelNames . INFO , isDevelopment : true , path : '/dev/null' , } ; describe ( 'global validation' , ( ) => { it ( 'should validate correctObjectMock' , async ( ) => { const errors = await validateDto ( correctObjectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toEqual ( [ ] ) ; } ) ; } ) ; describe ( 'level' , ( ) => { it ( 'should not accept values not in enum' , async ( ) => { const objectMock = { ... correctObjectMock , level : 'foo' , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'level' ) ; } ) ; } ) ; describe ( 'isDevelopment' , ( ) => { it ( 'shoud not allow truthy non boolean values' , async ( ) => { const objectMock = { ... correctObjectMock , isDevelopment : 'true' , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'isDevelopment' ) ; } ) ; it ( 'shoud not allow falsy non boolean values' , async ( ) => { const objectMock = { ... correctObjectMock , isDevelopment : '' , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'isDevelopment' ) ; } ) ; it ( 'shoud not allow null' , async ( ) => { const objectMock = { ... correctObjectMock , isDevelopment : null , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'isDevelopment' ) ; } ) ; it ( 'shoud not allow undefined' , async ( ) => { const objectMock = { ... correctObjectMock , isDevelopment : undefined , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'isDevelopment' ) ; } ) ; } ) ; describe ( 'path' , ( ) => { it ( 'should not accept empy value' , async ( ) => { const objectMock = { ... correctObjectMock , path : '' , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'path' ) ; } ) ; it ( 'should not accept boolean value' , async ( ) => { const objectMock = { ... correctObjectMock , path : true , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'path' ) ; } ) ; it ( 'should not accept array value' , async ( ) => { const objectMock = { ... correctObjectMock , path : [ ] , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'path' ) ; } ) ; it ( 'should not accept object value' , async ( ) => { const objectMock = { ... correctObjectMock , path : { } , } ; const errors = await validateDto ( objectMock , LoggerConfig , validationOptions ) ; expect ( errors ) . toHaveLength ( 1 ) ; expect ( errors [ 0 ] . property ) . toBe ( 'path' ) ; } ) ; } ) ; } ) ;