"use strict";

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

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

var _useFakeFetching = _interopRequireDefault(require("../../../../tests/util/useFakeFetching"));

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

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

var _constants = require("@instructure/quiz-common/lib/constants");

var _quizEntryRegrades = require("../quizEntryRegrades");

var _modal = require("../../../common/actions/modal");

describe('quizEntryRegrades', function () {
  describe('createQuizEntryRegrade', function () {
    var fetchStub = sinon.stub();
    var dispatchStub = sinon.stub();
    var getStateStub = sinon.stub();
    var quizId = '1';
    var payload = {
      itemId: '3',
      quizEntryId: '2',
      pointsPossible: 1.0,
      scoreReconciliation: 'new_score',
      scoringAlgorithm: 'Equivalence',
      scoringData: {
        value: true
      }
    };
    (0, _useFakeFetching.default)({
      dispatchStub: dispatchStub,
      getStateStub: getStateStub,
      fetchStub: fetchStub
    });
    it('hits the correct url', function () {
      var expectedUrl = "/api/quizzes/".concat(quizId, "/quiz_entry_regrades");
      _Fetcher.default.fakeFetch = fetchStub;
      (0, _quizEntryRegrades.createQuizEntryRegrade)(quizId, payload)(dispatchStub, getStateStub);
      expect(fetchStub).to.have.been.calledWith(expectedUrl);
    });
    it('closes the modal after creation', function (done) {
      var response = [];
      var fakeFetch = (0, _fakeFetch.default)((0, _jsonify.jsoniblePromise)(response));
      _Fetcher.default.fakeFetch = fakeFetch;
      var fetchPromise = (0, _quizEntryRegrades.createQuizEntryRegrade)(quizId, payload)(dispatchStub, getStateStub);
      fetchPromise.then(function () {
        expect(dispatchStub).to.have.been.calledWith((0, _modal.closeModal)(_constants.REGRADE_MODAL));
        done();
      });
    });
  });
});