handle moderator in store

This commit is contained in:
Moriz Wahl 2021-12-02 12:00:08 +01:00
parent 257e2e4073
commit 812722c53c
2 changed files with 16 additions and 2 deletions

View File

@ -26,6 +26,7 @@ export const mutations = {
export const actions = {
logout: ({ commit, state }) => {
commit('token', null)
commit('moderator', null)
window.localStorage.clear()
},
}
@ -38,7 +39,7 @@ const store = new Vuex.Store({
],
state: {
token: CONFIG.DEBUG_DISABLE_AUTH ? 'validToken' : null,
moderator: { name: 'Dertest Moderator', id: 0 },
moderator: null,
openCreations: 0,
},
// Syncronous mutation of the state

View File

@ -1,6 +1,6 @@
import store, { mutations, actions } from './store'
const { token, openCreationsPlus, openCreationsMinus, resetOpenCreations } = mutations
const { token, openCreationsPlus, openCreationsMinus, resetOpenCreations, moderator } = mutations
const { logout } = actions
const CONFIG = {
@ -40,6 +40,14 @@ describe('Vuex store', () => {
expect(state.openCreations).toEqual(0)
})
})
describe('moderator', () => {
it('sets the moderator object in state', () => {
const state = { moderator: null }
moderator(state, { id: 1 })
expect(state.moderator).toEqual({ id: 1 })
})
})
})
describe('actions', () => {
@ -57,6 +65,11 @@ describe('Vuex store', () => {
expect(commit).toBeCalledWith('token', null)
})
it('deletes the moderator in store', () => {
logout({ commit, state })
expect(commit).toBeCalledWith('moderator', null)
})
it.skip('clears the window local storage', () => {
expect(windowStorageMock).toBeCalled()
})