{"size": 1085, "ext": "js", "max_stars_repo_path": "src/__tests__/store/reducers/user.test.js", "max_stars_repo_name": "suneettipirneni/git-browser", "max_stars_repo_stars_event_min_datetime": "2021-02-16T23:14:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T09:31:31.000Z", "max_issues_repo_path": "src/__tests__/store/reducers/user.test.js", "max_issues_repo_name": "suneettipirneni/git-browser", "max_issues_repo_issues_event_min_datetime": "2021-05-28T22:48:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-28T23:03:32.000Z", "max_forks_repo_path": "src/__tests__/store/reducers/user.test.js", "max_forks_repo_name": "suneettipirneni/git-browser", "max_forks_repo_forks_event_min_datetime": "2021-05-03T21:30:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T20:54:53.000Z"}
{"max_stars_count": 4, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 21.2745098039, "max_line_length": 60, "alphanum_fraction": 0.5926267281}
import userReducer from 'src/store/reducers/user'

const initialState = {
  accessToken: '',
  username: '',
  isLoggedIn: false,
  isLoading: false
}

describe('user reducer', () => {
  test('returns initial state', () => {
    expect(userReducer(undefined, {})).toEqual(initialState)
  })

  test('handles LOGIN', () => {
    const action = {
      type: 'LOGIN',
      payload: {
        accessToken: 'mock-token',
        username: 'mock-user'
      }
    }

    expect(userReducer(initialState, action)).toEqual({
      ...initialState,
      accessToken: action.payload.accessToken,
      username: action.payload.username,
      isLoggedIn: true
    })
  })

  test('handles LOGOUT', () => {
    const action = { type: 'LOGOUT' }
    expect(userReducer({}, action)).toEqual(initialState)
  })

  test('handles TOGGLE_LOADING', () => {
    const action = {
      type: 'TOGGLE_LOADING',
      payload: {
        isLoading: true
      }
    }

    expect(userReducer(initialState, action)).toEqual({
      ...initialState,
      isLoading: action.payload.isLoading
    })
  })
})
