import * as ApiActions from './apiActions';
import { DEFAULT_TUTORIAL } from './constants/stepDefaults';

describe('apiActions', () => {
  describe('getEndpoints', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      ApiActions.getEndpoints(spy);
      expect(spy).toHaveBeenCalledWith({
        method: 'GET',
        path: 'tutorials/endpoints',
      });
    });
  });

  describe('getCodeSnippets', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      const 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', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      const payload = { page: {}, language: 'node', index: 1 };

      ApiActions.getCodeString(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/getCodeString',
        body: JSON.stringify(payload),
      });
    });
  });

  describe('createTutorial', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();

      ApiActions.createTutorial(spy, DEFAULT_TUTORIAL);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials',
        body: JSON.stringify(DEFAULT_TUTORIAL),
      });
    });
  });

  describe('updateTutorial', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      const payload = {
        ...DEFAULT_TUTORIAL,
        _id: '123',
      };

      ApiActions.updateTutorial(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'PUT',
        path: 'tutorials/123',
        body: JSON.stringify(payload),
      });
    });
  });

  describe('updateOnboarding', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      const payload = { endpoints: true };

      ApiActions.updateOnboarding(spy, payload);
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/onboarding',
        body: JSON.stringify(payload),
      });
    });
  });
});
