<commit_before>/* global jest, before, beforeEach, describe, it, expect */
jest.unmock('../../../modules/services/rules-service');

import * as RulesService from '../../../modules/services/rules-service';
import {assert, expect} from 'chai';

const fakeId = 'someId';
const idGenerator = {
  guid: () => fakeId
};
const ruleValue = "someValue";
const explicitRuleValue = {
  Id: fakeId,
  Matcher: {},
  Value: ruleValue,
  Type: "SingleVariant"
};


describe('rules-service', () => {
  describe('addPartition', () => {
    const partition = "somePartition";

    const rulesToCheck = [
      {expected: {'*': []}, partition, rules: [], depth: 0},
      {
        expected: {
          someValue: [{Matcher: {}}],
          '*': [{Matcher: {}}]
        },
        partition,
        rules: [{Matcher: {[partition]: 'someValue'}}, {Matcher: {}}],
        depth: 0
      },
      {
        expected: {
          partition1: {'someValue': [{Matcher: {}}], '*': [{Matcher: {}}]},
          partition2: {'*': []}
        },
        partition,
        rules: {
          partition1: [{Matcher: {[partition]: 'someValue'}}, {Matcher: {}}],
          partition2: []
        },
        depth: 1
      },
    ];

    rulesToCheck.forEach(({expected, partition, rules, depth}) => {
      it('should add partition', () => {
        const result = RulesService.addPartition(partition, rules, depth);
        assert.deepEqual(result, expected);
      })
    })
  });

  describe('convertToExplicitRules', () => {
    const rulesToCheck = [
      {
        expected: [explicitRuleValue],
        rule: ruleValue,
        depth: 0
      },
      {
        expected: [explicitRuleValue],
        rule: [explicitRuleValue],
        depth: 0
      },
      {
        expected: {'*': [explicitRuleValue]},
        rule: ruleValue,
        depth: 1
      },
      {
        expected: {'*': [explicitRuleValue]},
        rule: [explicitRuleValue],
        depth: 1
      },
      {
        expected: {
          somePartition1: [explicitRuleValue],
          somePartition2: [explicitRuleValue]
        },
        rule: {
          somePartition1: ruleValue,
          somePartition2: [explicitRuleValue]
        },
        depth: 1
      },
      {
        expected: {'*': {'*': [explicitRuleValue]}},
        rule: ruleValue,
        depth: 2
      },
      {
        expected: {'*': {'*': [explicitRuleValue]}},
        rule: [explicitRuleValue],
        depth: 2
      },
      {
        expected: {
          somePartition1: {'*': [explicitRuleValue]},
          somePartition2: {'*': [explicitRuleValue]},
          somePartition3: {innerPartition: [explicitRuleValue]},
          somePartition4: {innerPartition: [explicitRuleValue]}
        },
        rule: {
          somePartition1: ruleValue,
          somePartition2: [explicitRuleValue],
          somePartition3: {innerPartition: ruleValue},
          somePartition4: {innerPartition: [explicitRuleValue]}
        },
        depth: 2
      },
    ];

    rulesToCheck.forEach(({expected, rule, depth}) => {
      it('should convert to explicit', () => {
        const result = RulesService.convertToExplicitRules(rule, depth, idGenerator);
        assert.deepEqual(result, expected);
      });
    });
  });

  describe('convertToExplicitKey', () => {
    it ('should convert to explicit key', () => {
      const key = {
        partitions: ['p1','p2'],
        rules: {
          somePartition1: ruleValue,
          somePartition2: [explicitRuleValue],
          somePartition3: {innerPartition: ruleValue},
          somePartition4: {innerPartition: [explicitRuleValue]}
        },
        valueType: 'someType'
      };
      const expected = {
        partitions: ['p1','p2'],
        rules: {
          somePartition1: {'*': [explicitRuleValue]},
          somePartition2: {'*': [explicitRuleValue]},
          somePartition3: {innerPartition: [explicitRuleValue]},
          somePartition4: {innerPartition: [explicitRuleValue]}
        },
        valueType: 'someType'
      };
      const result = RulesService.convertToExplicitKey(key, idGenerator);
      assert.deepEqual(result, expected);
    });
  });
});<commit_msg>improve rules-service tests<commit_after>/* global jest, before, beforeEach, describe, it, expect */
jest.unmock('../../../modules/services/rules-service');

import * as RulesService from '../../../modules/services/rules-service';
import {assert, expect} from 'chai';

const fakeId = 'someId';
const idGenerator = {
  guid: () => fakeId
};
const toExplicitRule = (Value) => ({
  Id: fakeId,
  Matcher: {},
  Value,
  Type: "SingleVariant"

});

describe('rules-service', () => {
  describe('addPartition', () => {
    const partition = "somePartition";

    const rulesToCheck = [
      {expected: {'*': []}, partition, rules: [], depth: 0},
      {
        expected: {
          someValue1: [{Matcher: {}}],
          someValue2: [
            {Matcher: {}},
            {Matcher: {property: 'someValue'}}
          ],
          '*': [{Matcher: {}}]
        },
        partition,
        rules: [
          {Matcher: {[partition]: 'someValue1'}},
          {Matcher: {[partition]: 'someValue2'}},
          {Matcher: {[partition]: 'someValue2', property: 'someValue'}},
          {Matcher: {}}
        ],
        depth: 0
      },
      {
        expected: {
          partition1: {
            someValue: [
              {Matcher: {}},
              {Matcher: {property: 'someValue2'}}
            ],
            '*': [{Matcher: {}}]
          },
          partition2: {'*': []}
        },
        partition,
        rules: {
          partition1: [
            {Matcher: {[partition]: 'someValue'}},
            {Matcher: {[partition]: 'someValue', property: 'someValue2'}},
            {Matcher: {}}
          ],
          partition2: []
        },
        depth: 1
      },
    ];

    rulesToCheck.forEach(({expected, partition, rules, depth}) => {
      it('should add partition', () => {
        const result = RulesService.addPartition(partition, rules, depth);
        assert.deepEqual(result, expected);
      })
    })
  });

  describe('convertToExplicitRules', () => {
    const rulesToCheck = [
      {
        expected: [toExplicitRule("someValue")],
        rule: "someValue",
        depth: 0
      },
      {
        expected: [toExplicitRule("someValue")],
        rule: [toExplicitRule("someValue")],
        depth: 0
      },
      {
        expected: {'*': [toExplicitRule("someValue")]},
        rule: "someValue",
        depth: 1
      },
      {
        expected: {'*': [toExplicitRule("someValue")]},
        rule: [toExplicitRule("someValue")],
        depth: 1
      },
      {
        expected: {
          somePartition1: [toExplicitRule("someValue1")],
          somePartition2: [toExplicitRule("someValue2")]
        },
        rule: {
          somePartition1: "someValue1",
          somePartition2: [toExplicitRule("someValue2")]
        },
        depth: 1
      },
      {
        expected: {'*': {'*': [toExplicitRule("someValue")]}},
        rule: "someValue",
        depth: 2
      },
      {
        expected: {'*': {'*': [toExplicitRule("someValue")]}},
        rule: [toExplicitRule("someValue")],
        depth: 2
      },
      {
        expected: {
          somePartition1: {'*': [toExplicitRule("someValue1")]},
          somePartition2: {'*': [toExplicitRule("someValue2")]},
          somePartition3: {
            innerPartition1: [toExplicitRule("someValue3")],
            innerPartition2: [toExplicitRule("someValue4")]
          },
        },
        rule: {
          somePartition1: "someValue1",
          somePartition2: [toExplicitRule("someValue2")],
          somePartition3: {
            innerPartition1: "someValue3",
            innerPartition2: [toExplicitRule("someValue4")]
          },
        },
        depth: 2
      },
    ];

    rulesToCheck.forEach(({expected, rule, depth}) => {
      it('should convert to explicit', () => {
        const result = RulesService.convertToExplicitRules(rule, depth, idGenerator);
        assert.deepEqual(result, expected);
      });
    });
  });

  describe('convertToExplicitKey', () => {
    it('should convert to explicit key', () => {
      const key = {
        partitions: ['p1', 'p2'],
        rules: {
          somePartition1: "someValue1",
          somePartition2: [toExplicitRule("someValue2")],
          somePartition3: {innerPartition: "someValue3"},
          somePartition4: {innerPartition: [toExplicitRule("someValue4")]}
        },
        valueType: 'someType'
      };
      const expected = {
        partitions: ['p1', 'p2'],
        rules: {
          somePartition1: {'*': [toExplicitRule("someValue1")]},
          somePartition2: {'*': [toExplicitRule("someValue2")]},
          somePartition3: {innerPartition: [toExplicitRule("someValue3")]},
          somePartition4: {innerPartition: [toExplicitRule("someValue4")]}
        },
        valueType: 'someType'
      };
      const result = RulesService.convertToExplicitKey(key, idGenerator);
      assert.deepEqual(result, expected);
    });
  });
});
{'fraction_non_alphanumeric': 0.16401710338778644, 'fraction_numerical': 0.011731169827869752, 'mean_word_length': 2.1133105802047782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '670547', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2625, 'n_words': 475}