{"size": 1577, "ext": "js", "max_stars_repo_path": "src/containers/JobInfo/__tests__/action.test.js", "max_stars_repo_name": "joshand/react-collins-ui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/containers/JobInfo/__tests__/action.test.js", "max_issues_repo_name": "joshand/react-collins-ui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/containers/JobInfo/__tests__/action.test.js", "max_forks_repo_name": "joshand/react-collins-ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.435483871, "max_line_length": 76, "alphanum_fraction": 0.6207989854}
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import axios from 'axios';
import moxios from 'moxios';

import {
  fetchUser,
  USER_REQUESTING,
  USER_FAILURE,
  USER_SUCCESS,
  API_URL,
} from '../action';

const mockStore = configureMockStore([thunk]);

describe('fetch job data', () => {
  const jobId = '1';
  const response = {
    name: 'Welly',
    phone: '007',
    email: 'test@gmail.com',
    website: 'www.test.com',
  };
  const errorMessage = 'Oops! Something went wrong.';

  beforeEach(() => { moxios.install(); });

  afterEach(() => { moxios.uninstall(); });

  test('creates USER_SUCCESS when fetching user has been done', () => {
    moxios.stubRequest(API_URL, {
      status: 200,
      response: { data: response },
    });

    const expectedActions = [
      { type: USER_REQUESTING, userId },
      { type: USER_SUCCESS, userId, data: response },
    ];
    const store = mockStore({ info: null });

    store.dispatch(fetchUser(userId, axios))
      .then(() => { expect(store.getActions()).toEqual(expectedActions); });
  });

  test('creates USER_FAILURE when fail to fetch user', () => {
    moxios.stubRequest(API_URL + userId, {
      status: 400,
      response: { err: errorMessage },
    });

    const expectedActions = [
      { type: USER_REQUESTING, userId },
      { type: USER_FAILURE, userId, err: errorMessage },
    ];
    const store = mockStore({ err: null });

    store.dispatch(fetchUser(userId, axios))
      .then(() => { expect(store.getActions()).toEqual(expectedActions); });
  });
});
