{"size": 1751, "ext": "js", "max_stars_repo_path": "src/state/modules/auth.unit.js", "max_stars_repo_name": "hariprasad1143/vuejsexamples", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/state/modules/auth.unit.js", "max_issues_repo_name": "hariprasad1143/vuejsexamples", "max_issues_repo_issues_event_min_datetime": "2020-09-06T17:11:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T15:55:46.000Z", "max_forks_repo_path": "src/state/modules/auth.unit.js", "max_forks_repo_name": "hariprasad1143/vuejsexamples", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 27.359375, "max_line_length": 109, "alphanum_fraction": 0.6019417476}
import * as authModule from './auth'

describe('@state/modules/auth', () => {
  it('exports a valid Vuex module', () => {
    expect(authModule).toBeAVuexModule()
  })

  describe('in a store', () => {
    let store
    beforeEach(() => {
      store = createModuleStore(authModule)
    })

    test('getters.loggedIn returns true when currentUser is an object', () => {
      store.commit('SET_CURRENT_USER', {})
      expect(store.getters.loggedIn).toEqual(true)
    })

    test('getters.loggedIn returns false when currentUser is null', () => {
      store.commit('SET_CURRENT_USER', null)
      expect(store.getters.loggedIn).toEqual(false)
    })

    test('actions.logIn commits the currentUser and resolves to the user with username and password', () => {
      expect.assertions(2)

      return store
        .dispatch('logIn', { username: 'user', password: 'password' })
        .then(user => {
          expect(user).toEqual(validUserExample)
          expect(store.state.currentUser).toEqual(validUserExample)
        })
    })

    test('actions.logIn rejects with 401 when provided an incorrect username and password', () => {
      expect.assertions(1)

      return store
        .dispatch('logIn', {
          username: 'bad username',
          password: 'bad password',
        })
        .catch(error => {
          expect(error.message).toEqual('Request failed with status code 401')
        })
    })

    test('getters.logOut clears currentUser', () => {
      expect.assertions(1)

      store.commit('SET_CURRENT_USER', {})
      store.dispatch('logOut').then(() => {
        expect(store.state.currentUser).toEqual(null)
      })
    })
  })
})

const validUserExample = {
  id: 1,
  username: 'user',
  name: 'John Doe',
}
