<commit_before>import { LogMessage } from '../message';
import { Slack, Fluentd, Console } from '../service';
import Level from '../enum/level';
import Logger from '../logger';

describe('logger', () => {
  describe('config', () => {
    it('should accept object', () => {
      expect(() => new Logger({ key: 'value' })).not.toThrow('invalid config');
    });

    it('should not accept string', () => {
      expect(() => new Logger('not object')).toThrow('invalid config');
    });

    it('should not accept integer', () => {
      expect(() => new Logger(1)).toThrow('invalid config');
    });

    it('should not accept null', () => {
      expect(() => new Logger(null)).toThrow('invalid config');
    });

    it('should not accept array', () => {
      expect(() => new Logger([3, 4, 5])).toThrow('invalid config');
    });

    it('should initiate proper services according to config', () => {
      const originalSlackConfigCheck = Slack.prototype.IsConfigValid;
      const originalFluentdConfigCheck = Fluentd.prototype.IsConfigValid;
      const originalConsoleConfigCheck = Console.prototype.IsConfigValid;
      Slack.prototype.IsConfigValid = jest.fn(originalSlackConfigCheck);
      Fluentd.prototype.IsConfigValid = jest.fn(originalFluentdConfigCheck);
      Console.prototype.IsConfigValid = jest.fn(originalConsoleConfigCheck);

      const config = {
        base: {
          project: 'cool project',
          environment: 'production',
        },
        Slack: {
          logLevel: Level.DEBUG,
          slackToken: 'token',
          slackChannel: 'slack channel',
        },
        // disable console logger
        Console: false,
        // fluentd logger config is missing
      };

      const logger = new Logger(config);

      expect(logger.services).toHaveLength(1);
      expect(logger.services[0]).toBeInstanceOf(Slack);
      expect(logger.services[0].config).toEqual(
        Object.assign({}, config.base, config.Slack)
      );
      expect(Slack.prototype.IsConfigValid).toHaveBeenCalledTimes(1);
      expect(Fluentd.prototype.IsConfigValid).not.toHaveBeenCalled();
      expect(Console.prototype.IsConfigValid).not.toHaveBeenCalled();

      Slack.prototype.IsConfigValid = originalSlackConfigCheck;
      Fluentd.prototype.IsConfigValid = originalFluentdConfigCheck;
      Console.prototype.IsConfigValid = originalConsoleConfigCheck;
    });

    it('should accept process env override', () => {
      process.env.LOG_LEVEL = Level.INFO;

      const config = {
        base: {
          logLevel: Level.WARN,
          project: 'cool project',
          environment: 'production',
        },
        Slack: {
          logLevel: Level.ERROR,
          slackToken: 'token',
          slackChannel: 'slack channel',
        },
        Console: true,
        Fluentd: {
          collectorUrl: 'collector URL',
        },
      };

      const logger = new Logger(config);

      expect(logger.services).toHaveLength(3);
      expect(logger.services[0]).toBeInstanceOf(Slack);
      expect(logger.services[0].config).toEqual(
        Object.assign({}, config.base, config.Slack)
      );

      delete process.env.LOG_LEVEL;
    });<commit_msg>revert changes in logger test<commit_after>import { LogMessage } from '../message';
import { Slack, Fluentd, Console } from '../service';
import Level from '../enum/level';
import Logger from '../logger';

describe('logger', () => {
  describe('config', () => {
    it('should accept object', () => {
      expect(() => new Logger({ key: 'value' })).not.toThrow('invalid config');
    });

    it('should not accept string', () => {
      expect(() => new Logger('not object')).toThrow('invalid config');
    });

    it('should not accept integer', () => {
      expect(() => new Logger(1)).toThrow('invalid config');
    });

    it('should not accept null', () => {
      expect(() => new Logger(null)).toThrow('invalid config');
    });

    it('should not accept array', () => {
      expect(() => new Logger([3, 4, 5])).toThrow('invalid config');
    });

    it('should initiate proper services according to config', () => {
      const originalSlackConfigCheck = Slack.prototype.IsConfigValid;
      const originalFluentdConfigCheck = Fluentd.prototype.IsConfigValid;
      const originalConsoleConfigCheck = Console.prototype.IsConfigValid;
      Slack.prototype.IsConfigValid = jest.fn(originalSlackConfigCheck);
      Fluentd.prototype.IsConfigValid = jest.fn(originalFluentdConfigCheck);
      Console.prototype.IsConfigValid = jest.fn(originalConsoleConfigCheck);

      const config = {
        base: {
          project: 'cool project',
          environment: 'production',
        },
        Slack: {
          logLevel: Level.DEBUG,
          slackToken: 'token',
          slackChannel: 'slack channel',
        },
        // disable console logger
        Console: false,
        // fluentd logger config is missing
      };

      const logger = new Logger(config);

      expect(logger.services).toHaveLength(1);
      expect(logger.services[0]).toBeInstanceOf(Slack);
      expect(logger.services[0].config).toEqual(
        Object.assign({}, config.base, config.Slack)
      );
      expect(Slack.prototype.IsConfigValid).toHaveBeenCalledTimes(1);
      expect(Fluentd.prototype.IsConfigValid).not.toHaveBeenCalled();
      expect(Console.prototype.IsConfigValid).not.toHaveBeenCalled();

      Slack.prototype.IsConfigValid = originalSlackConfigCheck;
      Fluentd.prototype.IsConfigValid = originalFluentdConfigCheck;
      Console.prototype.IsConfigValid = originalConsoleConfigCheck;
    });
{'fraction_non_alphanumeric': 0.1441810728925325, 'fraction_numerical': 0.0033862056674389593, 'mean_word_length': 2.9244755244755245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2230502', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1531, 'n_words': 311}