"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

var _fs = _interopRequireDefault(require("fs"));

var _chai = require("chai");

var _assert = _interopRequireWildcard(require("assert"));

var _mocha = require("mocha");

var _nock = _interopRequireDefault(require("nock"));

var _LaunchDarklyUtils = require("../src/LaunchDarklyUtils");

var _LaunchDarklyUtilsProjects = require("../src/LaunchDarklyUtilsProjects");

var _LaunchDarklyLogger = require("../src/LaunchDarklyLogger");

// import { default as _ } from 'lodash';
var log = _LaunchDarklyLogger.LaunchDarklyLogger.logger();

(0, _mocha.describe)('LaunchDarklyUtilsFlags', function () {
  var ldutils;
  (0, _mocha.beforeEach)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return new _LaunchDarklyUtils.LaunchDarklyUtils().create('MOCK', log);

          case 2:
            ldutils = _context.sent;

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  (0, _mocha.describe)('fails to create utils', function () {
    try {
      new _LaunchDarklyUtilsProjects.LaunchDarklyUtilsProjects('MOCK', log, null);
      (0, _assert.fail)('Would not get here');
    } catch (e) {
      (0, _chai.expect)(e.message).to.equals('LaunchDarklyUtilsProjects constructor requires ldUtils parameter');
    }
  });
  (0, _mocha.describe)('getProjects successful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').get('/api/v2/projects').replyWithFile(200, __dirname + '/fixtures/projects-list.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      var expected;
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-list.json', 'utf-8'));
              return _context2.abrupt("return", ldutils.projects.getProjects().then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
              }));

            case 2:
            case "end":
              return _context2.stop();
          }
        }
      }, _callee2);
    })));
  });
  (0, _mocha.describe)('getProjects failed', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').get('/api/v2/projects').replyWithError({
        message: 'Something bad happened',
        code: '401'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      var expected;
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              expected = {
                api: 'getProjects',
                message: 'request to https://app.launchdarkly.com/api/v2/projects failed, reason: Something bad happened',
                docs: 'https://apidocs.launchdarkly.com/reference#list-projects'
              };
              return _context3.abrupt("return", ldutils.projects.getProjects().then(function () {
                (0, _assert.fail)('Would not get here');
              })["catch"](function (e) {
                (0, _chai.expect)(e).to.deep.equals(expected);
              }));

            case 2:
            case "end":
              return _context3.stop();
          }
        }
      }, _callee3);
    })));
  });
  (0, _mocha.describe)('getProject successful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').get('/api/v2/projects/abc123').replyWithFile(200, __dirname + '/fixtures/projects-get.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      var expected;
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-get.json', 'utf-8'));
              return _context4.abrupt("return", ldutils.projects.getProject('abc123').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
              }));

            case 2:
            case "end":
              return _context4.stop();
          }
        }
      }, _callee4);
    })));
  });
  (0, _mocha.describe)('getProject failed', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').get('/api/v2/projects/foo').replyWithError(404, {
        message: 'Unknown project key foo',
        code: '404'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var expected;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              expected = {
                api: 'getProject',
                message: 'request to https://app.launchdarkly.com/api/v2/projects/foo failed, reason: 404',
                docs: 'https://apidocs.launchdarkly.com/reference#get-project'
              };
              return _context5.abrupt("return", ldutils.projects.getProject('foo').then(function () {
                (0, _assert.fail)('Would not get here');
              })["catch"](function (e) {
                (0, _chai.expect)(e).to.deep.equals(expected);
              }));

            case 2:
            case "end":
              return _context5.stop();
          }
        }
      }, _callee5);
    })));
  });
  (0, _mocha.describe)('createProject successful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects').replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var expected, environments;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              environments = 'dev,Development,blue';
              return _context6.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'true', environments).then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
              }));

            case 3:
            case "end":
              return _context6.stop();
          }
        }
      }, _callee6);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key and name only', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      var expected;
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context7.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: []
                });
              }));

            case 2:
            case "end":
              return _context7.stop();
          }
        }
      }, _callee7);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key and name and includeInSnippetByDefault as true', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
      var expected;
      return _regenerator["default"].wrap(function _callee8$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context8.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'true').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  includeInSnippetByDefault: true,
                  tags: []
                });
              }));

            case 2:
            case "end":
              return _context8.stop();
          }
        }
      }, _callee8);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key and name and includeInSnippetByDefault as false', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
      var expected;
      return _regenerator["default"].wrap(function _callee9$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context9.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'false').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  includeInSnippetByDefault: false,
                  tags: []
                });
              }));

            case 2:
            case "end":
              return _context9.stop();
          }
        }
      }, _callee9);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, includeInSnippetByDefault and environment', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
      var expected;
      return _regenerator["default"].wrap(function _callee10$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context10.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'false', 'dev,Development,blue').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  includeInSnippetByDefault: false,
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }]
                });
              }));

            case 2:
            case "end":
              return _context10.stop();
          }
        }
      }, _callee10);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, environment and usingEnvironmentId is true', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11() {
      var expected;
      return _regenerator["default"].wrap(function _callee11$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context11.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', undefined, 'dev,Development,blue', 'true').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  defaultClientSideAvailability: {
                    usingEnvironmentId: true,
                    usingMobileKey: true
                  }
                });
              }));

            case 2:
            case "end":
              return _context11.stop();
          }
        }
      }, _callee11);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, environment and usingEnvironmentId is false', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12() {
      var expected;
      return _regenerator["default"].wrap(function _callee12$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context12.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', undefined, 'dev,Development,blue', 'false').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  defaultClientSideAvailability: {
                    usingEnvironmentId: false,
                    usingMobileKey: true
                  }
                });
              }));

            case 2:
            case "end":
              return _context12.stop();
          }
        }
      }, _callee12);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, environment ,usingEnvironmentId and mobileKey is true', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
      var expected;
      return _regenerator["default"].wrap(function _callee13$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context13.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', undefined, 'dev,Development,blue', 'true', 'true').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  defaultClientSideAvailability: {
                    usingEnvironmentId: true,
                    usingMobileKey: true
                  }
                });
              }));

            case 2:
            case "end":
              return _context13.stop();
          }
        }
      }, _callee13);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, environment ,usingEnvironmentId and mobileKey is false', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14() {
      var expected;
      return _regenerator["default"].wrap(function _callee14$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context14.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', undefined, 'dev,Development,blue', 'true', 'false').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  defaultClientSideAvailability: {
                    usingEnvironmentId: true,
                    usingMobileKey: false
                  }
                });
              }));

            case 2:
            case "end":
              return _context14.stop();
          }
        }
      }, _callee14);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, includeInSnippetByDefault, environment ,usingEnvironmentId and mobileKey', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15() {
      var expected;
      return _regenerator["default"].wrap(function _callee15$(_context15) {
        while (1) {
          switch (_context15.prev = _context15.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context15.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'true', 'dev,Development,blue', 'true', 'false').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: [],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  includeInSnippetByDefault: true
                });
              }));

            case 2:
            case "end":
              return _context15.stop();
          }
        }
      }, _callee15);
    })));
  });
  (0, _mocha.describe)('createProject successful with project key, name, includeInSnippetByDefault, environment ,usingEnvironmentId, mobileKey and tags', function () {
    var postBody;
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects', function (body) {
        postBody = body;
        return body;
      }).replyWithFile(201, __dirname + '/fixtures/projects-create.json', {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16() {
      var expected;
      return _regenerator["default"].wrap(function _callee16$(_context16) {
        while (1) {
          switch (_context16.prev = _context16.next) {
            case 0:
              expected = JSON.parse(_fs["default"].readFileSync(__dirname + '/fixtures/projects-create.json', 'utf-8'));
              return _context16.abrupt("return", ldutils.projects.createProject('testProject', 'Test Project', 'true', 'dev,Development,blue', 'true', 'true', 'foo,bar').then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal(expected);
                (0, _chai.expect)(postBody).to.deep.equal({
                  key: 'testProject',
                  name: 'Test Project',
                  tags: ['foo', 'bar'],
                  environments: [{
                    key: 'dev',
                    name: 'Development',
                    color: 'blue'
                  }],
                  includeInSnippetByDefault: true
                });
              }));

            case 2:
            case "end":
              return _context16.stop();
          }
        }
      }, _callee16);
    })));
  });
  (0, _mocha.describe)('createProject unsuccessful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').post('/api/v2/projects').replyWithError({
        message: 'Account already has a project with that key',
        code: '409'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17() {
      var expected, tags, environments;
      return _regenerator["default"].wrap(function _callee17$(_context17) {
        while (1) {
          switch (_context17.prev = _context17.next) {
            case 0:
              expected = {
                api: 'createProject',
                message: 'request to https://app.launchdarkly.com/api/v2/projects failed, reason: Account already has a project with that key',
                docs: 'https://apidocs.launchdarkly.com/reference#create-project'
              };
              tags = 'foo,bar';
              environments = 'dev,Development,blue';
              return _context17.abrupt("return", ldutils.projects.createProject('fooProject', 'Foo Project', true, environments, tags).then(function () {
                (0, _assert.fail)('Would not get here');
              })["catch"](function (e) {
                (0, _chai.expect)(e).to.deep.equals(expected);
              }));

            case 4:
            case "end":
              return _context17.stop();
          }
        }
      }, _callee17);
    })));
  });
  (0, _mocha.describe)('updateProject successful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').patch('/api/v2/projects/abc123').reply(200, {});
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18() {
      var jsonPatch;
      return _regenerator["default"].wrap(function _callee18$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              jsonPatch = [{
                op: 'replace',
                path: '/name',
                value: 'New project name'
              }];
              return _context18.abrupt("return", ldutils.projects.updateProject('abc123', jsonPatch).then(function (actual) {
                (0, _chai.expect)(actual).to.deep.equal({});
              }));

            case 2:
            case "end":
              return _context18.stop();
          }
        }
      }, _callee18);
    })));
  });
  (0, _mocha.describe)('updateProject unsuccessful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com').patch('/api/v2/projects/abc123').replyWithError({
        message: 'Unsupported json-patch operation',
        code: '400'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19() {
      var expected, jsonPatch;
      return _regenerator["default"].wrap(function _callee19$(_context19) {
        while (1) {
          switch (_context19.prev = _context19.next) {
            case 0:
              expected = {
                api: 'patchProject',
                message: 'request to https://app.launchdarkly.com/api/v2/projects/abc123 failed, reason: Unsupported json-patch operation',
                docs: 'https://apidocs.launchdarkly.com/reference#update-project'
              };
              jsonPatch = [{
                op: 'replace',
                path: '/baz',
                value: 'boo'
              }, {
                op: 'add',
                path: '/hello',
                value: ['world']
              }, {
                op: 'remove',
                path: '/foo'
              }];
              return _context19.abrupt("return", ldutils.projects.updateProject('abc123', jsonPatch).then(function () {
                (0, _assert.fail)('Would not get here');
              })["catch"](function (e) {
                (0, _chai.expect)(e).to.deep.equals(expected);
              }));

            case 3:
            case "end":
              return _context19.stop();
          }
        }
      }, _callee19);
    })));
  });
  (0, _mocha.describe)('deleteProject successful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com')["delete"]('/api/v2/projects/abc123').reply(204, undefined, {
        'Content-Type': 'application/json'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20() {
      return _regenerator["default"].wrap(function _callee20$(_context20) {
        while (1) {
          switch (_context20.prev = _context20.next) {
            case 0:
              return _context20.abrupt("return", ldutils.projects.deleteProject('abc123').then(function (actual) {
                (0, _chai.expect)(actual).to.be.undefined;
              }));

            case 1:
            case "end":
              return _context20.stop();
          }
        }
      }, _callee20);
    })));
  });
  (0, _mocha.describe)('deleteProject unsuccessful', function () {
    (0, _mocha.before)(function (done) {
      var scope = (0, _nock["default"])('https://app.launchdarkly.com')["delete"]('/api/v2/projects/foo').replyWithError({
        message: 'Unknown project key foo',
        code: '404'
      });
      (0, _assert["default"])(scope);
      done();
    });
    (0, _mocha.it)('should make expected api call and return results', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21() {
      var expected;
      return _regenerator["default"].wrap(function _callee21$(_context21) {
        while (1) {
          switch (_context21.prev = _context21.next) {
            case 0:
              expected = {
                api: 'deleteProject',
                message: 'request to https://app.launchdarkly.com/api/v2/projects/foo failed, reason: Unknown project key foo',
                docs: 'https://apidocs.launchdarkly.com/reference#delete-project'
              };
              return _context21.abrupt("return", ldutils.projects.deleteProject('foo').then(function () {
                (0, _assert.fail)('Would not get here');
              })["catch"](function (e) {
                (0, _chai.expect)(e).to.deep.equals(expected);
              }));

            case 2:
            case "end":
              return _context21.stop();
          }
        }
      }, _callee21);
    })));
  });
  (0, _mocha.describe)('getTags', function () {
    (0, _mocha.it)('Should return multiple tags when there are multiple records', function () {
      var expected = ['abc', 'def'];
      var acutual = ldutils.projects.getTagsArray('abc,def');
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
    (0, _mocha.it)('Should return a single tag when there are single record', function () {
      var expected = ['abc'];
      var acutual = ldutils.projects.getTagsArray('abc');
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
    (0, _mocha.it)('Should return an empty array when there is no entry', function () {
      var expected = [];
      var acutual = ldutils.projects.getTagsArray(undefined);
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
  });
  (0, _mocha.describe)('getEnvironmentItem', function () {
    (0, _mocha.it)('Should return an environment item when a proper string is passed in', function () {
      var expected = {
        key: 'dev',
        name: 'Development',
        color: '417505'
      };
      var acutual = ldutils.projects.getEnvironmentItem('dev,Development,417505');
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
    (0, _mocha.it)('Should throw an error if the input less than three items', function () {
      try {
        ldutils.projects.getEnvironmentItem('dev,Development');
        (0, _assert.fail)('Would not get here');
      } catch (e) {
        console.log('exception is ' + JSON.stringify(e));
        (0, _chai.expect)(e).to.equals('Invalid environments configuration, should have 3 items, key, name and colour');
      }
    });
    (0, _mocha.it)('Should throw an error if the inpiut is undefined', function () {
      try {
        ldutils.projects.getEnvironmentItem(undefined);
        (0, _assert.fail)('Would not get here');
      } catch (e) {
        (0, _chai.expect)(e).to.equals('Invalid environments configuration, should have 3 items, key, name and colour');
      }
    });
  });
  (0, _mocha.describe)('getEnvironmentsArray', function () {
    (0, _mocha.it)('Should return multiple environments when a string containing environment seperator', function () {
      var expected = [{
        key: 'dev',
        name: 'Development',
        color: '417505'
      }, {
        key: 'test',
        name: 'Test',
        color: 'f5a623'
      }];
      var acutual = ldutils.projects.getEnvironmentsArray('dev,Development,417505:test,Test,f5a623');
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
    (0, _mocha.it)('Should return single environments when a string does not contain an environment seperator', function () {
      var expected = [{
        key: 'dev',
        name: 'Development',
        color: '417505'
      }];
      var acutual = ldutils.projects.getEnvironmentsArray('dev,Development,417505');
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
    (0, _mocha.it)('Should return an empty array if the environment string provided is empty', function () {
      var expected = undefined;
      var acutual = ldutils.projects.getEnvironmentsArray(undefined);
      (0, _chai.expect)(acutual).to.deep.equals(expected);
    });
  });
});