/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { inject, TestBed } from '@angular/core/testing';
import { CoreConfig } from '../core-configuration/core-config';
import { CORE_CONFIG } from '../core-configuration/core-config.token';
import { LoggerService } from './logger.service';
import { LogLevel } from './loglevel';

describe('ConsoleLoggerService', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        {
          provide: CORE_CONFIG,
          useValue: <CoreConfig>{ environment: 'test', endpointNavigation: 'nix' },
        },
      ],
    });
  });

  it('should log error log on loglevel information', inject([LoggerService], (service: LoggerService) => {
    service.logLevel = LogLevel.INFORMATION;
    jest.spyOn(console, 'error').mockReset();
    service.error('example error');
    expect(console.error).toHaveBeenCalledWith('[ERROR] example error', expect.any(Object));
  }));

  it('should log trace on console.log', inject([LoggerService], (service: LoggerService) => {
    service.logLevel = LogLevel.TRACE;
    jest.spyOn(console, 'log').mockReset();
    service.trace('bla blub');
    expect(console.log).toHaveBeenCalledWith('[TRACE] bla blub', expect.any(Object));
  }));

  it('should not show trace on loglevel information', inject([LoggerService], (service: LoggerService) => {
    service.logLevel = LogLevel.INFORMATION;
    jest.spyOn(console, 'log').mockReset();
    service.trace('harhar');
    expect(console.log).toHaveBeenCalledTimes(0);
  }));
});
