'use strict';

var _chai;

function _load_chai() {
  return _chai = require('chai');
}

var _sources;

function _load_sources() {
  return _sources = _interopRequireDefault(require('../../../src/scope/repositories/sources'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

describe('SourceRepository', function () {
  describe('mergeTwoComponentsObjects', function () {
    var sources = void 0;
    before(function () {
      sources = new (_sources || _load_sources()).default();
    });
    it('should not remove a version that exist locally but not in the incoming component', function () {
      var existingComponent = {
        versions: {
          '0.0.1': '3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e',
          '0.0.2': 'c471678f719783b044ac6d933ccb1da7132dc93d'
        }
      };
      var incomingComponent = {
        versions: { '0.0.1': '3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e' }
      };
      var mergedComponent = sources.mergeTwoComponentsObjects(existingComponent, incomingComponent);
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions).to.have.property('0.0.2');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions['0.0.2']).to.equal('c471678f719783b044ac6d933ccb1da7132dc93d');
    });
    it('should override a version from the incoming component in case of hash discrepancies', function () {
      var existingComponent = {
        versions: { '0.0.1': '3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e' }
      };
      var incomingComponent = {
        versions: { '0.0.1': 'c471678f719783b044ac6d933ccb1da7132dc93d' }
      };
      var mergedComponent = sources.mergeTwoComponentsObjects(existingComponent, incomingComponent);
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions['0.0.1']).to.equal('c471678f719783b044ac6d933ccb1da7132dc93d');
    });
    it('should add versions that exist in the incoming component but not locally', function () {
      var existingComponent = {
        versions: { '0.0.1': '3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e' }
      };
      var incomingComponent = {
        versions: {
          '0.0.1': '3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e',
          '0.0.2': 'c471678f719783b044ac6d933ccb1da7132dc93d',
          '0.0.3': '56f2b008f43c20f6538ef27023759c3d9a44992c'
        }
      };
      var mergedComponent = sources.mergeTwoComponentsObjects(existingComponent, incomingComponent);
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions).to.have.property('0.0.1');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions).to.have.property('0.0.2');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions).to.have.property('0.0.3');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions['0.0.1']).to.equal('3d4f647fb943437b675e7163ed1e4d1f7c8a8c0e');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions['0.0.2']).to.equal('c471678f719783b044ac6d933ccb1da7132dc93d');
      (0, (_chai || _load_chai()).expect)(mergedComponent.versions['0.0.3']).to.equal('56f2b008f43c20f6538ef27023759c3d9a44992c');
    });
  });
});