import { createServiceFactory, SpectatorService } from '@ngneat/spectator';
import { ConsoleLogProvider } from './console-log.provider';
import { LogLevel } from './log-level';

describe('ConsoleLogProvider', () => {
  let spectator: SpectatorService<ConsoleLogProvider>;

  const createService = createServiceFactory({
    service: ConsoleLogProvider,
  });

  beforeEach(() => {
    spectator = createService();
  });

  it('should create', () => {
    expect(spectator.service).toBeTruthy();
  });

  describe('log', () => {
    it('should call console.debug', () => {
      spyOn(console, 'debug');
      spectator.service.log(LogLevel.DEBUG, 'test');
      expect(console.debug).toHaveBeenCalledWith('test');
    });

    it('should call console.info', () => {
      spyOn(console, 'info');
      spectator.service.log(LogLevel.INFO, 'test');
      expect(console.info).toHaveBeenCalledWith('test');
    });

    it('should call console.warn', () => {
      spyOn(console, 'warn');
      spectator.service.log(LogLevel.WARN, 'test');
      expect(console.warn).toHaveBeenCalledWith('test');
    });

    it('should call console.error', () => {
      spyOn(console, 'error');
      spectator.service.log(LogLevel.ERROR, 'test');
      expect(console.error).toHaveBeenCalledWith('test');
    });

    it('should not call console.log', () => {
      spyOn(console, 'log');
      spectator.service.log(LogLevel.OFF, 'test');
      expect(console.log).not.toHaveBeenCalled();
    });
  });
});
