import { mockCreateLayout } from './appenders.test.mocks' ; import { LegacyAppender } from '../../legacy/logging/appenders/legacy_appender' ; import { Appenders } from './appenders' ; import { ConsoleAppender } from './console/console_appender' ; import { FileAppender } from './file/file_appender' ; beforeEach ( ( ) => { mockCreateLayout . mockReset ( ) ; } ) ; test ( '`configSchema` creates correct schema.' , ( ) => { const appendersSchema = Appenders . configSchema ; const validConfig1 = { kind : 'file' , layout : { kind : 'mock' } , path : 'path' } ; expect ( appendersSchema . validate ( validConfig1 ) ) . toEqual ( { kind : 'file' , layout : { kind : 'mock' } , path : 'path' , } ) ; const validConfig2 = { kind : 'console' , layout : { kind : 'mock' } } ; expect ( appendersSchema . validate ( validConfig2 ) ) . toEqual ( { kind : 'console' , layout : { kind : 'mock' } , } ) ; const wrongConfig1 = { kind : 'console' , layout : { kind : 'mock' } , path : 'path' , } ; expect ( ( ) => appendersSchema . validate ( wrongConfig1 ) ) . toThrow ( ) ; const wrongConfig2 = { kind : 'file' , layout : { kind : 'mock' } } ; expect ( ( ) => appendersSchema . validate ( wrongConfig2 ) ) . toThrow ( ) ; const wrongConfig3 = { kind : 'console' , layout : { kind : 'mock' } , path : 'path' , } ; expect ( ( ) => appendersSchema . validate ( wrongConfig3 ) ) . toThrow ( ) ; } ) ; test ( '`create()` creates correct appender.' , ( ) => { mockCreateLayout . mockReturnValue ( { format : ( ) => '' } ) ; const consoleAppender = Appenders . create ( { kind : 'console' , layout : { highlight : true , kind : 'pattern' , pattern : '' } , } ) ; expect ( consoleAppender ) . toBeInstanceOf ( ConsoleAppender ) ; const fileAppender = Appenders . create ( { kind : 'file' , layout : { highlight : true , kind : 'pattern' , pattern : '' } , path : 'path' , } ) ; expect ( fileAppender ) . toBeInstanceOf ( FileAppender ) ; const legacyAppender = Appenders . create ( { kind : 'legacy-appender' , legacyLoggingConfig : { verbose : true } , } ) ; expect ( legacyAppender ) . toBeInstanceOf ( LegacyAppender ) ; } ) ;