<commit_before>/* eslint-env mocha */

'use strict';

let chai = require('chai');
let expect = chai.expect;
let dirtyChai = require('dirty-chai');
let chaiAsPromised = require('chai-as-promised');
let Ajv = require('ajv');

let schema = require('../../../lib/schema/itemHierarchy');

chai.use(dirtyChai);
chai.use(chaiAsPromised);

describe('Item Hierarchy JSON', () => {
  let ajv = new Ajv();
  let validJSON = false;
  let failingTestCases = [
    {title: 'should return false for empty JSON', body: {}},
    {title: 'should return false when id field is missing from an item',
      body: {items: [
        {name: 'story', type: 35, children: []}
      ]}
    },
    {title: 'should return false when name field is missing from an item',
      body: {items: [
        {id: 1, type: 35, children: []}
      ]}
    },
    {title: 'should return false when type field is missing from an item',
      body: {items: [
        {id: 1, name: 'story', children: []}
      ]}
    },
    {title: 'should return false when children are missing from an item',
      body: {items: [
        {id: 1, name: 'story', type: 35}
      ]}
    },
    {title: 'should return false when id field is a string',
      body: {items: [
        {id: '1', name: 'story', type: 35, children: []}
      ]}
    },
    {title: 'should return false when name field is an integer',
      body: {items: [
        {id: 1, name: 123, type: 35, children: []}
      ]}
    },
    {title: 'should return false when type field is a string',
      body: {items: [
        {id: 1, name: 'story', type: '35', children: []}
      ]}
    }
  ];
  let passingTestCases = [
    {title: 'should return true when JSON populates each required field with at least one element once',
      body: {items: [
        {id: 1, name: 'story', type: 35, children: []}
      ]}
    },
    {title: 'should return true when JSON contains many items in the item hierarchy tree',
      body: {items: [
        {id: 1, name: 'story', type: 35, children: [
            {id: 2, name: 'bug', type: 40, children: []},
            {id: 3, name: 'task', type: 45, children: []}
        ]},
        {id: 10, name: 'story', type: 35, children: [
            {id: 4, name: 'task', type: 45, children: []}
        ]},
        {id: 11, name: 'story', type: 35, children: []}
      ]}
    }
  ];
  failingTestCases.forEach(item => {
    it(item.title, () => {
      validJSON = ajv.validate(schema, item.body);
      expect(validJSON).to.be.false();
    });
  });
  passingTestCases.forEach(item => {
    it(item.title, () => {
      validJSON = ajv.validate(schema, item.body);
      expect(validJSON).to.be.true();
    });
  });
});<commit_msg>Updated schema tests for itemHierarchy to now include the parent and isSet properties<commit_after>/* eslint-env mocha */

'use strict';

let chai = require('chai');
let expect = chai.expect;
let dirtyChai = require('dirty-chai');
let chaiAsPromised = require('chai-as-promised');
let Ajv = require('ajv');

let schema = require('../../../lib/schema/itemHierarchy');

chai.use(dirtyChai);
chai.use(chaiAsPromised);

describe('Item Hierarchy JSON', () => {
  let ajv = new Ajv();
  let validJSON = false;
  let failingTestCases = [
    {title: 'should return false for empty JSON', body: {}},
    {title: 'should return false when id field is missing from an item',
      body: {items: [
        {name: 'story', type: 35, children: []}
      ]}
    },
    {title: 'should return false when name field is missing from an item',
      body: {items: [
        {id: 1, type: 35, children: []}
      ]}
    },
    {title: 'should return false when type field is missing from an item',
      body: {items: [
        {id: 1, name: 'story', children: []}
      ]}
    },
    {title: 'should return false when children are missing from an item',
      body: {items: [
        {id: 1, name: 'story', type: 35}
      ]}
    },
    {title: 'should return false when id field is a string',
      body: {items: [
        {id: '1', name: 'story', type: 35, children: []}
      ]}
    },
    {title: 'should return false when name field is an integer',
      body: {items: [
        {id: 1, name: 123, type: 35, children: []}
      ]}
    },
    {title: 'should return false when type field is a string',
      body: {items: [
        {id: 1, name: 'story', type: '35', children: []}
      ]}
    }
  ];
  let passingTestCases = [
    {title: 'should return true when JSON populates each required field with at least one element once',
      body: {items: [
        {id: 1, name: 'story', type: 35, parent: 33, isSet: false, children: []}
      ]}
    },
    {title: 'should return true when JSON contains many items in the item hierarchy tree',
      body: {items: [
        {id: 1, name: 'story', type: 35, parent: 33, isSet: true, children: [
            {id: 2, name: 'bug', type: 40, parent: 1, isSet: false, children: []},
            {id: 3, name: 'task', type: 45, parent: 1, isSet: false, children: []}
        ]},
        {id: 10, name: 'story', type: 35, parent: 33, isSet: true, children: [
            {id: 4, name: 'task', type: 45, parent: 10, isSet: false, children: []}
        ]},
        {id: 11, name: 'story', type: 35, parent: 33, isSet: false, children: []}
      ]}
    }
  ];
  failingTestCases.forEach(item => {
    it(item.title, () => {
      validJSON = ajv.validate(schema, item.body);
      expect(validJSON).to.be.false();
    });
  });
  passingTestCases.forEach(item => {
    it(item.title, () => {
      validJSON = ajv.validate(schema, item.body);
      expect(validJSON).to.be.true();
    });
  });
});
{'fraction_non_alphanumeric': 0.16946728637826242, 'fraction_numerical': 0.01787629603146228, 'mean_word_length': 2.5166561910747958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6518539', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1825, 'n_words': 590}