diff --git a/admin/src/store/store.js b/admin/src/store/store.js index 5f8b4249d..754c559c8 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -23,7 +23,7 @@ export const mutations = { export const actions = { logout: ({ commit, state }) => { commit('token', null) - localStorage.clear() + window.localStorage.clear() }, } diff --git a/admin/src/store/store.test.js b/admin/src/store/store.test.js index 81d75f05f..4482a46bf 100644 --- a/admin/src/store/store.test.js +++ b/admin/src/store/store.test.js @@ -1,6 +1,11 @@ -import { mutations } from './store' +import store, { mutations, actions } from './store' const { token, openCreationsPlus, openCreationsMinus, resetOpenCreations } = mutations +const { logout } = actions + +const CONFIG = { + DEBUG_DISABLE_AUTH: true, +} describe('Vuex store', () => { describe('mutations', () => { @@ -36,4 +41,43 @@ describe('Vuex store', () => { }) }) }) + + describe('actions', () => { + describe('logout', () => { + const windowStorageMock = jest.fn() + const commit = jest.fn() + const state = {} + beforeEach(() => { + jest.clearAllMocks() + window.localStorage.clear = windowStorageMock + }) + + it('deletes the token in store', () => { + logout({ commit, state }) + expect(commit).toBeCalledWith('token', null) + }) + + it.skip('clears the window local storage', () => { + expect(windowStorageMock).toBeCalled() + }) + }) + }) + + describe('state', () => { + describe('authentication enabled', () => { + it('has no token', () => { + expect(store.state.token).toBe(null) + }) + }) + + describe('authentication enabled', () => { + beforeEach(() => { + CONFIG.DEBUG_DISABLE_AUTH = false + }) + + it.skip('has a token', () => { + expect(store.state.token).toBe('validToken') + }) + }) + }) })