<commit_before>/* eslint-disable global-require */

describe('lib/Validator.js', () => {
  describe('testFile1', () => {
    test('constructor', () => {
      const Validator = require('../../lib/Validator.js');
      const options = 'options';

      const validator = new Validator(options);

      expect(validator.options).toBe(options);
    });
    test('run', () => {
      const Validator = require('../../lib/Validator.js');
      Validator.checkAvailabilityRequiredFields = fn();
      Validator.checkTypes = fn();
      const options = 'options';
      const mocThis = { options };

      const validator = new Validator();
      validator.run.call(mocThis);

      expect(Validator.checkAvailabilityRequiredFields).toHaveBeenCalledTimes(1);
      expect(Validator.checkAvailabilityRequiredFields).toHaveBeenCalledWith(options);

      expect(Validator.checkTypes).toHaveBeenCalledTimes(1);
      expect(Validator.checkTypes).toHaveBeenCalledWith(options);
    });
    // genTest('module.exports workflow', function* () {
    //   const wrapper = require('../../lib/Validator.js');
    //
    //   jest.mock('../../lib/ReplaceInFiles');
    //   const ReplaceInFiles = require('../../lib/ReplaceInFiles');
    //   const paths = 'paths';
    //   const moc = { run: pFn(paths) };
    //   ReplaceInFiles.mockImplementation(() => moc);
    //
    //   const options = 'options';
    //   const result = yield wrapper.init(options);
    //
    // expect(ReplaceInFiles).toHaveBeenCalledTimes(1);
    // expect(ReplaceInFiles).toHaveBeenCalledWith(options);
    //
    // expect(moc.run).toHaveBeenCalledTimes(1);
    // expect(moc.run).toHaveBeenCalledWith();
    //
    //   expect(result).toBe(paths);
    // });
  });
});<commit_msg>tests validator - check required fields<commit_after>/* eslint-disable global-require */

describe('lib/Validator.js', () => {
  describe('testFile1', () => {
    test('constructor', () => {
      const Validator = require('../../lib/Validator.js');
      const options = 'options';

      const validator = new Validator(options);

      expect(validator.options).toBe(options);
    });
    test('run', () => {
      const Validator = require('../../lib/Validator.js');
      Validator.checkAvailabilityRequiredFields = fn();
      Validator.checkTypes = fn();
      const options = 'options';
      const mocThis = { options };

      const validator = new Validator();
      validator.run.call(mocThis);

      expect(Validator.checkAvailabilityRequiredFields).toHaveBeenCalledTimes(1);
      expect(Validator.checkAvailabilityRequiredFields).toHaveBeenCalledWith(options);

      expect(Validator.checkTypes).toHaveBeenCalledTimes(1);
      expect(Validator.checkTypes).toHaveBeenCalledWith(options);
    });
    test('checkAvailabilityRequiredFields', () => {
      const Validator = require('../../lib/Validator.js');
      const config = require('../../lib/config.json');
      config.Validator.requiredOptions = ['foo', 'bar'];
      Validator.checkAvailabilityRequiredField = fn();
      const options = {
        foo: '1',
        bar: '2',
        test: '3',
      };

      Validator.checkAvailabilityRequiredFields(options);

      expect(Validator.checkAvailabilityRequiredField).toHaveBeenCalledTimes(2);
      expect(Validator.checkAvailabilityRequiredField).toHaveBeenCalledWith(options.foo, 'foo');
      expect(Validator.checkAvailabilityRequiredField).toHaveBeenCalledWith(options.bar, 'bar');
    });
    describe('checkAvailabilityRequiredField', () => {
      test('pass 1', () => {
        const Validator = require('../../lib/Validator.js');
        const value = 'exist';
        const key = 'FieldName';

        Validator.checkAvailabilityRequiredField(value, key);
      });
      test('pass 2', () => {
        const Validator = require('../../lib/Validator.js');
        const value = true;
        const key = 'FieldName';

        Validator.checkAvailabilityRequiredField(value, key);
      });
      test('pass 3', () => {
        const Validator = require('../../lib/Validator.js');
        const value = null;
        const key = 'FieldName';

        Validator.checkAvailabilityRequiredField(value, key);
      });
      test('pass 4', () => {
        const Validator = require('../../lib/Validator.js');
        const value = '';
        const key = 'FieldName';

        Validator.checkAvailabilityRequiredField(value, key);
      });
      test('throw', () => {
        const Validator = require('../../lib/Validator.js');
        const value = undefined;
        const key = 'FieldName';

        expect(() => Validator.checkAvailabilityRequiredField(value, key))
          .toThrow('option — "FieldName" is required!');
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.16649059792943166, 'fraction_numerical': 0.003380519754912318, 'mean_word_length': 2.8239095315024234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '1339764', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1280, 'n_words': 211}