mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
store without session ID
This commit is contained in:
parent
02a70c5acf
commit
235eefad3a
@ -12,9 +12,6 @@ export const mutations = {
|
||||
email: (state, email) => {
|
||||
state.email = email
|
||||
},
|
||||
sessionId: (state, sessionId) => {
|
||||
state.sessionId = sessionId
|
||||
},
|
||||
username: (state, username) => {
|
||||
state.username = username
|
||||
},
|
||||
@ -35,23 +32,21 @@ export const mutations = {
|
||||
export const actions = {
|
||||
login: ({ dispatch, commit }, token) => {
|
||||
const decoded = VueJwtDecode.decode(token)
|
||||
commit('sessionId', decoded.sessionId)
|
||||
commit('token', token)
|
||||
commit('email', decoded.email)
|
||||
commit('language', decoded.language)
|
||||
commit('username', decoded.username)
|
||||
commit('firstName', decoded.firstName)
|
||||
commit('lastName', decoded.lastName)
|
||||
commit('description', decoded.description)
|
||||
commit('token', token)
|
||||
},
|
||||
logout: ({ commit, state }) => {
|
||||
commit('sessionId', null)
|
||||
commit('token', null)
|
||||
commit('email', null)
|
||||
commit('username', '')
|
||||
commit('firstName', '')
|
||||
commit('lastName', '')
|
||||
commit('description', '')
|
||||
commit('token', null)
|
||||
localStorage.clear()
|
||||
},
|
||||
}
|
||||
@ -63,7 +58,6 @@ export const store = new Vuex.Store({
|
||||
}),
|
||||
],
|
||||
state: {
|
||||
sessionId: null,
|
||||
email: '',
|
||||
language: null,
|
||||
firstName: '',
|
||||
|
||||
@ -1,6 +1,17 @@
|
||||
import { mutations, actions } from './store'
|
||||
import VueJwtDecode from 'vue-jwt-decode'
|
||||
|
||||
const { language, email, sessionId, username, firstName, lastName, description } = mutations
|
||||
jest.mock('vue-jwt-decode')
|
||||
VueJwtDecode.decode.mockReturnValue({
|
||||
email: 'user@example.org',
|
||||
language: 'de',
|
||||
username: 'peter',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
description: 'Nickelbrille',
|
||||
})
|
||||
|
||||
const { language, email, token, username, firstName, lastName, description } = mutations
|
||||
const { login, logout } = actions
|
||||
|
||||
describe('Vuex store', () => {
|
||||
@ -21,11 +32,11 @@ describe('Vuex store', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('sessionId', () => {
|
||||
it('sets the state of sessionId', () => {
|
||||
const state = { sessionId: null }
|
||||
sessionId(state, '1234')
|
||||
expect(state.sessionId).toEqual('1234')
|
||||
describe('token', () => {
|
||||
it('sets the state of token', () => {
|
||||
const state = { token: null }
|
||||
token(state, '1234')
|
||||
expect(state.token).toEqual('1234')
|
||||
})
|
||||
})
|
||||
|
||||
@ -66,41 +77,31 @@ describe('Vuex store', () => {
|
||||
describe('login', () => {
|
||||
const commit = jest.fn()
|
||||
const state = {}
|
||||
const commitedData = {
|
||||
sessionId: 1234,
|
||||
user: {
|
||||
email: 'someone@there.is',
|
||||
language: 'en',
|
||||
username: 'user',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
description: 'Nickelbrille',
|
||||
},
|
||||
}
|
||||
const commitedData = 'token'
|
||||
|
||||
it('calls seven commits', () => {
|
||||
login({ commit, state }, commitedData)
|
||||
expect(commit).toHaveBeenCalledTimes(7)
|
||||
})
|
||||
|
||||
it('commits sessionId', () => {
|
||||
it('commits token', () => {
|
||||
login({ commit, state }, commitedData)
|
||||
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', 1234)
|
||||
expect(commit).toHaveBeenNthCalledWith(1, 'token', 'token')
|
||||
})
|
||||
|
||||
it('commits email', () => {
|
||||
login({ commit, state }, commitedData)
|
||||
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'someone@there.is')
|
||||
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'user@example.org')
|
||||
})
|
||||
|
||||
it('commits language', () => {
|
||||
login({ commit, state }, commitedData)
|
||||
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'en')
|
||||
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'de')
|
||||
})
|
||||
|
||||
it('commits username', () => {
|
||||
login({ commit, state }, commitedData)
|
||||
expect(commit).toHaveBeenNthCalledWith(4, 'username', 'user')
|
||||
expect(commit).toHaveBeenNthCalledWith(4, 'username', 'peter')
|
||||
})
|
||||
|
||||
it('commits firstName', () => {
|
||||
@ -128,9 +129,9 @@ describe('Vuex store', () => {
|
||||
expect(commit).toHaveBeenCalledTimes(6)
|
||||
})
|
||||
|
||||
it('commits sessionId', () => {
|
||||
it('commits token', () => {
|
||||
logout({ commit, state })
|
||||
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', null)
|
||||
expect(commit).toHaveBeenNthCalledWith(1, 'token', null)
|
||||
})
|
||||
|
||||
it('commits email', () => {
|
||||
@ -159,7 +160,7 @@ describe('Vuex store', () => {
|
||||
})
|
||||
|
||||
// how to get this working?
|
||||
it.skip('calls sessionStorage.clear()', () => {
|
||||
it.skip('calls localStorage.clear()', () => {
|
||||
const clearStorageMock = jest.fn()
|
||||
global.sessionStorage = jest.fn(() => {
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user