feat: init
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { AbstractLoggerService } from './abstract-logger.service';
|
||||
import { ConsoleLoggerService } from './console-logger.service';
|
||||
import { LogLevel } from './log-level';
|
||||
@@ -26,7 +27,7 @@ describe('Logger Service', () => {
|
||||
|
||||
describe('logError', () => {
|
||||
it('should not log error if loglevel is None', () => {
|
||||
const spy = spyOn(console, 'error');
|
||||
const spy = vi.spyOn(console, 'error');
|
||||
|
||||
loggerService.logError(
|
||||
{ configId: 'configId1', logLevel: LogLevel.None },
|
||||
@@ -36,23 +37,25 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should log error as default if error is string', () => {
|
||||
const spy = spyOn(console, 'error');
|
||||
const spy = vi.spyOn(console, 'error');
|
||||
|
||||
loggerService.logError({ configId: 'configId1' }, 'some message');
|
||||
expect(spy).toHaveBeenCalledOnceWith('[ERROR] configId1 - some message');
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[ERROR] configId1 - some message'
|
||||
);
|
||||
});
|
||||
|
||||
it('should log error as default if error is object', () => {
|
||||
const spy = spyOn(console, 'error');
|
||||
const spy = vi.spyOn(console, 'error');
|
||||
|
||||
loggerService.logError({ configId: 'configId1' }, { some: 'message' });
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[ERROR] configId1 - {"some":"message"}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should always log error with args', () => {
|
||||
const spy = spyOn(console, 'error');
|
||||
const spy = vi.spyOn(console, 'error');
|
||||
|
||||
loggerService.logError(
|
||||
{ configId: 'configId1' },
|
||||
@@ -60,7 +63,7 @@ describe('Logger Service', () => {
|
||||
'arg1',
|
||||
'arg2'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[ERROR] configId1 - some message',
|
||||
'arg1',
|
||||
'arg2'
|
||||
@@ -70,7 +73,7 @@ describe('Logger Service', () => {
|
||||
|
||||
describe('logWarn', () => {
|
||||
it('should not log if no log level is set (null)', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: undefined },
|
||||
@@ -80,14 +83,14 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should not log if no config is given', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning({}, 'some message');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not log if no log level is set (undefined)', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning({ configId: 'configId1' }, 'some message');
|
||||
|
||||
@@ -95,7 +98,7 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should not log if log level is turned off', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.None },
|
||||
@@ -105,29 +108,31 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should log warning when loglevel is Warn and message is string', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Warn },
|
||||
'some message'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith('[WARN] configId1 - some message');
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[WARN] configId1 - some message'
|
||||
);
|
||||
});
|
||||
|
||||
it('should log warning when loglevel is Warn and message is object', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Warn },
|
||||
{ some: 'message' }
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[WARN] configId1 - {"some":"message"}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should log warning when loglevel is Warn with args', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Warn },
|
||||
@@ -135,7 +140,7 @@ describe('Logger Service', () => {
|
||||
'arg1',
|
||||
'arg2'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[WARN] configId1 - some message',
|
||||
'arg1',
|
||||
'arg2'
|
||||
@@ -143,17 +148,19 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should log warning when loglevel is Debug', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Debug },
|
||||
'some message'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith('[WARN] configId1 - some message');
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[WARN] configId1 - some message'
|
||||
);
|
||||
});
|
||||
|
||||
it('should not log warning when loglevel is error', () => {
|
||||
const spy = spyOn(console, 'warn');
|
||||
const spy = vi.spyOn(console, 'warn');
|
||||
|
||||
loggerService.logWarning(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Error },
|
||||
@@ -165,7 +172,7 @@ describe('Logger Service', () => {
|
||||
|
||||
describe('logDebug', () => {
|
||||
it('should not log if no log level is set (null)', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: undefined },
|
||||
@@ -175,14 +182,14 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should not log if no log level is set (undefined)', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug({ configId: 'configId1' }, 'some message');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not log if log level is turned off', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.None },
|
||||
@@ -192,29 +199,31 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should log when loglevel is Debug and value is string', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Debug },
|
||||
'some message'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith('[DEBUG] configId1 - some message');
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[DEBUG] configId1 - some message'
|
||||
);
|
||||
});
|
||||
|
||||
it('should log when loglevel is Debug and value is object', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Debug },
|
||||
{ some: 'message' }
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[DEBUG] configId1 - {"some":"message"}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should log when loglevel is Debug with args', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Debug },
|
||||
@@ -222,7 +231,7 @@ describe('Logger Service', () => {
|
||||
'arg1',
|
||||
'arg2'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'[DEBUG] configId1 - some message',
|
||||
'arg1',
|
||||
'arg2'
|
||||
@@ -230,7 +239,7 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should not log when loglevel is Warn', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Warn },
|
||||
@@ -240,7 +249,7 @@ describe('Logger Service', () => {
|
||||
});
|
||||
|
||||
it('should not log when loglevel is error', () => {
|
||||
const spy = spyOn(console, 'debug');
|
||||
const spy = vi.spyOn(console, 'debug');
|
||||
|
||||
loggerService.logDebug(
|
||||
{ configId: 'configId1', logLevel: LogLevel.Error },
|
||||
|
||||
Reference in New Issue
Block a user