"use strict";

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

var _Fetcher = _interopRequireDefault(require("../../util/Fetcher"));

var _fakeFetch = _interopRequireDefault(require("../../../../tests/util/fakeFetch"));

var _jsonify = require("../../util/jsonify");

var _features = require("../../actions/features");

var _features2 = require("../features");

describe('features api action', function () {
  describe('getFeatures', function () {
    var fetchStub = sinon.stub();
    var dispatchStub = sinon.stub();
    var getStateStub = sinon.stub();
    useFakeFetching({
      dispatchStub: dispatchStub,
      getStateStub: getStateStub,
      fetchStub: fetchStub
    });
    it('hits the correct url', function () {
      var expectedUrl = '/api/features';
      _Fetcher.default.fakeFetch = fetchStub;
      (0, _features2.getFeatures)()(dispatchStub, getStateStub);
      expect(fetchStub.calledWith(expectedUrl)).to.be.true();
    });
    it('dispatches addFeatures with the response', function (done) {
      var response = ['feature1', 'feature2'];
      var fakeFetch = (0, _fakeFetch.default)((0, _jsonify.jsoniblePromise)(response));
      _Fetcher.default.fakeFetch = fakeFetch;
      var fetchPromise = (0, _features2.getFeatures)()(dispatchStub, getStateStub);
      fetchPromise.then(function () {
        expect(dispatchStub.calledWith((0, _features.addFeatures)(response))).to.be.true();
        done();
      });
    });
  });
});