import * as ApiActions from './apiActions';

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

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

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

  describe('makeHero', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      ApiActions.makeHero(spy, { _id: '123' });
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/123/makeHero',
      });
    });
  });

  describe('shiftOrder', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      ApiActions.shiftOrder(spy, { _id: '123', direction: 1 });
      expect(spy).toHaveBeenCalledWith({
        method: 'POST',
        path: 'tutorials/123/shiftOrder',
        body: JSON.stringify({ _id: '123', direction: 1 }),
      });
    });
  });

  describe('updateTutorial', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      ApiActions.updateTutorial(spy, { _id: '123', published: true });
      expect(spy).toHaveBeenCalledWith({
        method: 'PUT',
        path: 'tutorials/123',
        body: JSON.stringify({ _id: '123', published: true }),
      });
    });
  });

  describe('deleteTutorial', () => {
    it('should send the correct option payload', () => {
      const spy = jest.fn();
      ApiActions.deleteTutorial(spy, { _id: '123' });
      expect(spy).toHaveBeenCalledWith({
        method: 'DELETE',
        path: 'tutorials/123',
      });
    });
  });
});
