"use strict";

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

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

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

var ApiActions = _interopRequireWildcard(require("./apiActions"));

var _stepDefaults = require("./constants/stepDefaults");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

describe('apiActions', function () {
  describe('getEndpoints', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();
      ApiActions.getEndpoints(spy);
      expect(spy).toHaveBeenCalledWith({
        method: 'GET',
        path: 'tutorials/endpoints'
      });
    });
  });
  describe('getCodeSnippets', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();
      var payload = {
        page: {},
        codeOptions: [{
          code: '',
          language: 'node',
          name: 'Node'
        }]
      };
      ApiActions.getCodeSnippets(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/getCodeSnippets',
        body: JSON.stringify(payload)
      });
    });
  });
  describe('getCodeString', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();
      var payload = {
        page: {},
        language: 'node',
        index: 1
      };
      ApiActions.getCodeString(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/getCodeString',
        body: JSON.stringify(payload)
      });
    });
  });
  describe('createTutorial', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();
      ApiActions.createTutorial(spy, _stepDefaults.DEFAULT_TUTORIAL);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials',
        body: JSON.stringify(_stepDefaults.DEFAULT_TUTORIAL)
      });
    });
  });
  describe('updateTutorial', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();

      var payload = _objectSpread(_objectSpread({}, _stepDefaults.DEFAULT_TUTORIAL), {}, {
        _id: '123'
      });

      ApiActions.updateTutorial(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'PUT',
        path: 'tutorials/123',
        body: JSON.stringify(payload)
      });
    });
  });
  describe('updateOnboarding', function () {
    it('should send the correct option payload', function () {
      var spy = jest.fn();
      var payload = {
        endpoints: true
      };
      ApiActions.updateOnboarding(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/onboarding',
        body: JSON.stringify(payload)
      });
    });
  });
});