<commit_before>import Group from '../../models/group';
import User from '../../models/user';
import EscalationPolicy from '../../models/escalationPolicy';
import { equalDates } from '../helpers/dateHelper';
import { build, fixtures } from '../../utils/factories';

describe('## Group Model', () => {
  const subscriberRotationIntervalInDays = 7;
  const subscriberPagingIntervalInMinutes = 15;
  const subscriberObjectId = '<KEY>';

  const escPolicy = {
    rotationIntervalInDays: subscriberRotationIntervalInDays,
    pagingIntervalInMinutes: subscriberPagingIntervalInMinutes,
    subscribers: [subscriberObjectId]
  };

  const userObjectId = '<KEY>';
  let group = null;

  context('# with a valid group', () => {
    const groupData = {
      name: 'Wondertwins',
      users: [userObjectId],
    };

    it('should create a new group', (done) => {
      new Group(groupData).save((err, newGroup) => {
        const compareEP = EscalationPolicy.defaultEscalationPolicy();
        const newGroupEP = newGroup.escalationPolicy;
        expect(err).to.not.exist;
        expect(newGroup.name).to.equal(groupData.name);
        expect(newGroup.users[0].toString()).to.equal(groupData.users[0]);
        expect(newGroupEP.pagingIntervalInMinutes).to.equal(compareEP.pagingIntervalInMinutes);
        expect(newGroupEP.rotationIntervalInDays).to.equal(compareEP.rotationIntervalInDays);
        expect(newGroupEP.subscribers).to.be.empty;
        expect(equalDates(newGroup.lastRotated, new Date())).to.eq(true);
        done();
      });
    });
  });

  context('# with a passed in date', () => {
    const date = new Date(2018, 8, 15, 18, 56, 30);

    const groupObj = fixtures.group({ lastRotated: date });

    it('should create a new group with that date', (done) => {
      new Group(groupObj).save((err, newGroup) => {
        expect(newGroup.name).to.equal(groupObj.name);
        expect(equalDates(newGroup.lastRotated, date)).to.eq(true);
        done();
      });
    });
  });

  context('# when name is not there', () => {
    const groupData = {
      users: [userObjectId],
      escalationPolicy: escPolicy
    };

    before(() => {
      group = new Group(groupData);
    });

    it('should not create a new group', (done) => {
      group.save((err, newGroup) => {
        expect(err).to.exist;
        expect(err.errors.name.message).to.equal('Path `name` is required.');
        done();
      });
    });
  });

  describe('# group user modifications', () => {
    const baseGroup = fixtures.group({
      users: []
    });

    const newUser = new User({
      name: '<NAME>',
      email: '<EMAIL>'
    });

    beforeEach((done) => {
      build('group', baseGroup)
        .then((newGroup) => {
          group = newGroup;
          done();
        });
    });

    it('should add a user to the group', (done) => {
      group.addUser(newUser.id)
        .then((receivedGroup) => {
          expect(receivedGroup).to.exist;
          expect(receivedGroup.name).to.equal(baseGroup.name);
          expect(receivedGroup.users).to.not.be.empty;
          done();
        });
    });

    it('should remove a user from the group', (done) => {
      group.addUser(newUser.id)
        .then(modifiedGroup => expect(modifiedGroup.users[0]).to.exist)
        .then(() => group.removeUser(newUser.id))
        .then((receivedGroup) => {
          expect(receivedGroup).to.exist;
          expect(receivedGroup.users).to.be.empty;
          done();
        });
    });
  });
});
<commit_msg>Add getAllGroups() test<commit_after>import Group from '../../models/group';
import User from '../../models/user';
import EscalationPolicy from '../../models/escalationPolicy';
import { equalDates } from '../helpers/dateHelper';
import { build, fixtures } from '../../utils/factories';

describe('## Group Model', () => {
  const subscriberRotationIntervalInDays = 7;
  const subscriberPagingIntervalInMinutes = 15;
  const subscriberObjectId = '<KEY>';

  const escPolicy = {
    rotationIntervalInDays: subscriberRotationIntervalInDays,
    pagingIntervalInMinutes: subscriberPagingIntervalInMinutes,
    subscribers: [subscriberObjectId]
  };

  const userObjectId = '<KEY>';
  let group;

  context('# with a valid group', () => {
    const groupData = {
      name: 'Wondertwins',
      users: [userObjectId],
    };

    it('should create a new group', (done) => {
      new Group(groupData).save((err, newGroup) => {
        const compareEP = EscalationPolicy.defaultEscalationPolicy();
        const newGroupEP = newGroup.escalationPolicy;
        expect(err).to.not.exist;
        expect(newGroup.name).to.equal(groupData.name);
        expect(newGroup.users[0].toString()).to.equal(groupData.users[0]);
        expect(newGroupEP.pagingIntervalInMinutes).to.equal(compareEP.pagingIntervalInMinutes);
        expect(newGroupEP.rotationIntervalInDays).to.equal(compareEP.rotationIntervalInDays);
        expect(newGroupEP.subscribers).to.be.empty;
        expect(equalDates(newGroup.lastRotated, new Date())).to.eq(true);
        done();
      });
    });
  });

  context('# with a passed in date', () => {
    const date = new Date(2018, 8, 15, 18, 56, 30);

    const groupObj = fixtures.group({ lastRotated: date });

    it('should create a new group with that date', (done) => {
      new Group(groupObj).save((err, newGroup) => {
        expect(newGroup.name).to.equal(groupObj.name);
        expect(equalDates(newGroup.lastRotated, date)).to.eq(true);
        done();
      });
    });
  });

  context('# when name is not there', () => {
    const groupData = {
      users: [userObjectId],
      escalationPolicy: escPolicy
    };

    before(() => {
      group = new Group(groupData);
    });

    it('should not create a new group', (done) => {
      group.save((err, newGroup) => {
        expect(err).to.exist;
        expect(err.errors.name.message).to.equal('Path `name` is required.');
        done();
      });
    });
  });

  describe('# group user modifications', () => {
    const baseGroup = fixtures.group({
      users: []
    });

    const newUser = new User({
      name: '<NAME>',
      email: '<EMAIL>'
    });

    beforeEach((done) => {
      build('group', baseGroup)
        .then((newGroup) => {
          group = newGroup;
          done();
        });
    });

    it('should add a user to the group', (done) => {
      group.addUser(newUser.id)
        .then((receivedGroup) => {
          expect(receivedGroup).to.exist;
          expect(receivedGroup.name).to.equal(baseGroup.name);
          expect(receivedGroup.users).to.not.be.empty;
          done();
        });
    });

    it('should remove a user from the group', (done) => {
      group.addUser(newUser.id)
        .then(modifiedGroup => expect(modifiedGroup.users[0]).to.exist)
        .then(() => group.removeUser(newUser.id))
        .then((receivedGroup) => {
          expect(receivedGroup).to.exist;
          expect(receivedGroup.users).to.be.empty;
          done();
        });
    });
  });

  describe('# get all groups', () => {
    const baseGroup = fixtures.group();

    beforeEach((done) => {
      build('group', baseGroup)
        .then(() => build('group', baseGroup))
        .then(() => build('group', baseGroup))
        .then(() => done());
    });

    it('should return 3 groups', (done) => {
      Group.getAllGroups()
        .then((groups) => {
          expect(groups).to.exist;
          expect(groups).to.have.lengthOf(3);
          done();
        });
    });
  });
});

{'fraction_non_alphanumeric': 0.16622340425531915, 'fraction_numerical': 0.005319148936170213, 'mean_word_length': 2.6580739299610894, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 58, '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': '799442', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2238, 'n_words': 437}