"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

function _path() {
  const data = _interopRequireDefault(require("path"));

  _path = function () {
    return data;
  };

  return data;
}

function _chai() {
  const data = require("chai");

  _chai = function () {
    return data;
  };

  return data;
}

function _dataToPersist() {
  const data = _interopRequireDefault(require("./data-to-persist"));

  _dataToPersist = function () {
    return data;
  };

  return data;
}

describe('DataToPersist', function () {
  this.timeout(0);
  describe('addFile', () => {
    describe('dir/file collision', () => {
      it('should not throw when the existing file starts with the added file in the same dir', () => {
        const dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: 'foo/bar.js'
        });

        const addFile = () => dataToPersist.addFile({
          path: _path().default.normalize('foo/bar.json')
        });

        (0, _chai().expect)(addFile).to.not.throw();
      });
      it('should not throw when the added file starts with the existing file in the same dir', () => {
        const dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('foo/bar.json')
        });

        const addFile = () => dataToPersist.addFile({
          path: _path().default.normalize('foo/bar.js')
        });

        (0, _chai().expect)(addFile).to.not.throw();
      });
      it('should throw when the added file is a directory of the existing file', () => {
        const dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('foo/bar.js')
        });

        const addFile = () => dataToPersist.addFile({
          path: 'foo'
        });

        (0, _chai().expect)(addFile).to.throw();
      });
      it('should throw when the existing file is a directory of the added file', () => {
        const dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: 'foo'
        });

        const addFile = () => dataToPersist.addFile({
          path: _path().default.normalize('foo/bar.js')
        });

        (0, _chai().expect)(addFile).to.throw();
      });
      it('should throw when one is a directory of other with a few levels', () => {
        let dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('foo1/foo2')
        });

        const addFile1 = () => dataToPersist.addFile({
          path: _path().default.normalize('foo1/foo2/foo3/foo4')
        });

        (0, _chai().expect)(addFile1).to.throw();
        dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('foo1/foo2/foo3/foo4')
        });

        const addFile2 = () => dataToPersist.addFile({
          path: _path().default.normalize('foo1/foo2')
        });

        (0, _chai().expect)(addFile2).to.throw();
      });
      it('should not throw when file are different', () => {
        let dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: 'bar'
        });

        const addFile1 = () => dataToPersist.addFile({
          path: 'foo'
        });

        (0, _chai().expect)(addFile1).to.not.throw();
        dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: 'foo'
        });

        const addFile2 = () => dataToPersist.addFile({
          path: 'bar'
        });

        (0, _chai().expect)(addFile2).to.not.throw();
      });
      it('should not throw when file are different with the same dir', () => {
        let dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('bar/foo.js')
        });

        const addFile1 = () => dataToPersist.addFile({
          path: _path().default.normalize('bar/baz.js')
        });

        (0, _chai().expect)(addFile1).to.not.throw();
        dataToPersist = new (_dataToPersist().default)();
        dataToPersist.addFile({
          path: _path().default.normalize('bar/baz.js')
        });

        const addFile2 = () => dataToPersist.addFile({
          path: _path().default.normalize('bar/foo.js')
        });

        (0, _chai().expect)(addFile2).to.not.throw();
      });
    });
  });
});