<commit_before>describe('diffArray module', function() {
  beforeEach(angular.mock.module('diffArray'));

  describe('diffArray service', function() {
    var diffArray,
        deepCopyRemovals,
        deepCopyChanges;

    beforeEach(angular.mock.inject(function(_diffArray_, _deepCopyRemovals_, _deepCopyChanges_) {
      diffArray = _diffArray_;
      deepCopyRemovals = _deepCopyRemovals_;
      deepCopyChanges = _deepCopyChanges_;
    }));

    it('should notify addedAt and changedAt changes between two arrays', function() {
      var addedDoc = {_id: "c", b: 1};
      var oldCollection = [
        {_id: "a", identical: "property"},
        {_id: "b", first: 2, second: {firstNested: "b"}, willBeRemoved: ":'("}
      ];
      var newCollection = [
        {_id: "a", identical: "property"},
        {_id: "b", first: 2, second: {nestedInSecond: "a"}, third: "hello"},
        addedDoc
      ];
      var addedAtSpy = jasmine.createSpy('addedAt');
      var changedAtSpy = jasmine.createSpy('changedAt');

      diffArray(oldCollection, newCollection, {
        addedAt: addedAtSpy,
        changedAt: changedAtSpy,
      });

      expect(addedAtSpy).toHaveBeenCalledWith(addedDoc._id, addedDoc, 2, jasmine.any(Object));
      expect(changedAtSpy).toHaveBeenCalledWith(
        'b',
        {_id: "b", "second.nestedInSecond": "a", "third": "hello"},
        {_id: "b", "second.firstNested": true, willBeRemoved: true},
        1,
        jasmine.any(Object));
    });

    describe('when comparing two arrays with two different dates', function() {
      it('should notify callback with changedAt', function() {
        var oldCollection = [{
          _id: "a", date: new Date(1111, 1, 1)
        }];
        var newCollection = [{
          _id: "a", date: new Date(2222, 2, 2)
        }];
        var changedAtSpy = jasmine.createSpy('changedAt');

        diffArray(oldCollection, newCollection, { changedAt: changedAtSpy });

        expect(changedAtSpy).toHaveBeenCalledWith(
          'a',
          {_id: "a", date: new Date(2222, 2, 2)},
          undefined,
          0,
          jasmine.any(Object));
      });
    });

    describe('deepCopyRemovals', function() {
      it('should handle fields that are false-y correctly', function() {
        var oldItem = {_id: 1, field : 0, another : 3};
        var newItem = {_id: 1, field : 0};

        deepCopyRemovals(oldItem, newItem);<commit_msg>(Tests): Add failing test when comparing $$hashkeys<commit_after>describe('diffArray module', function() {
  beforeEach(angular.mock.module('diffArray'));

  describe('diffArray service', function() {
    var diffArray,
        deepCopyRemovals,
        deepCopyChanges;

    beforeEach(angular.mock.inject(function(_diffArray_, _deepCopyRemovals_, _deepCopyChanges_) {
      diffArray = _diffArray_;
      deepCopyRemovals = _deepCopyRemovals_;
      deepCopyChanges = _deepCopyChanges_;
    }));

    it('should notify addedAt and changedAt changes between two arrays', function() {
      var addedDoc = {_id: "c", b: 1};
      var oldCollection = [
        {_id: "a", identical: "property"},
        {_id: "b", first: 2, second: {firstNested: "b"}, willBeRemoved: ":'("}
      ];
      var newCollection = [
        {_id: "a", identical: "property"},
        {_id: "b", first: 2, second: {nestedInSecond: "a"}, third: "hello"},
        addedDoc
      ];
      var addedAtSpy = jasmine.createSpy('addedAt');
      var changedAtSpy = jasmine.createSpy('changedAt');

      diffArray(oldCollection, newCollection, {
        addedAt: addedAtSpy,
        changedAt: changedAtSpy,
      });

      expect(addedAtSpy).toHaveBeenCalledWith(addedDoc._id, addedDoc, 2, jasmine.any(Object));
      expect(changedAtSpy).toHaveBeenCalledWith(
        'b',
        {_id: "b", "second.nestedInSecond": "a", "third": "hello"},
        {_id: "b", "second.firstNested": true, willBeRemoved: true},
        1,
        jasmine.any(Object));
    });

    describe('when comparing two arrays with two different dates', function() {
      it('should notify callback with changedAt', function() {
        var oldCollection = [{
          _id: "a", date: new Date(1111, 1, 1)
        }];
        var newCollection = [{
          _id: "a", date: new Date(2222, 2, 2)
        }];
        var changedAtSpy = jasmine.createSpy('changedAt');

        expect(function(){diffArray(oldCollection, newCollection, { changedAt: changedAtSpy })}).not.toThrow();

        expect(changedAtSpy).toHaveBeenCalledWith(
          'a',
          {_id: "a", date: new Date(2222, 2, 2)},
          undefined,
          0,
          jasmine.any(Object));
      });
    });

    describe('no exception on first compare and ignore $$hashkeys', function() {
      it('should notify callback with changedAt', function() {
        var oldCollection = [{
          _id: "a", date: new Date(1111, 1, 1), checked: true, $$hashKey: "object:4"
        },
        {
          _id: "b", date: new Date(2222, 2, 2), checked: true, $$hashKey: "object:6"
        },
        {
          _id: "c", date: new Date(2222, 2, 2), checked: true, $$hashKey: "object:8"
        }];
        var newCollection = [{
          _id: "a", date: new Date(1111, 1, 1), checked: true
        },
        {
          _id: "b", date: new Date(2222, 2, 2), checked: false
        },
        {
          _id: "c", date: new Date(2222, 2, 2), checked: true
        }];
        var changedAtSpy = jasmine.createSpy('changedAt');

        expect(function(){diffArray(oldCollection, newCollection, { changedAt: changedAtSpy })}).not.toThrow();

        expect(changedAtSpy).toHaveBeenCalledWith(
          'b',
          {checked: false, _id: "b"},
          undefined,
          1,
          jasmine.any(Object));
      });
    });

    describe('deepCopyRemovals', function() {
      it('should handle fields that are false-y correctly', function() {
        var oldItem = {_id: 1, field : 0, another : 3};
        var newItem = {_id: 1, field : 0};

        deepCopyRemovals(oldItem, newItem);
{'fraction_non_alphanumeric': 0.14643449419568821, 'fraction_numerical': 0.01625207296849088, 'mean_word_length': 2.6135410425404433, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '6641665', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1846, 'n_words': 454}