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) => {
|
email: (state, email) => {
|
||||||
state.email = email
|
state.email = email
|
||||||
},
|
},
|
||||||
sessionId: (state, sessionId) => {
|
|
||||||
state.sessionId = sessionId
|
|
||||||
},
|
|
||||||
username: (state, username) => {
|
username: (state, username) => {
|
||||||
state.username = username
|
state.username = username
|
||||||
},
|
},
|
||||||
@ -35,23 +32,21 @@ export const mutations = {
|
|||||||
export const actions = {
|
export const actions = {
|
||||||
login: ({ dispatch, commit }, token) => {
|
login: ({ dispatch, commit }, token) => {
|
||||||
const decoded = VueJwtDecode.decode(token)
|
const decoded = VueJwtDecode.decode(token)
|
||||||
commit('sessionId', decoded.sessionId)
|
commit('token', token)
|
||||||
commit('email', decoded.email)
|
commit('email', decoded.email)
|
||||||
commit('language', decoded.language)
|
commit('language', decoded.language)
|
||||||
commit('username', decoded.username)
|
commit('username', decoded.username)
|
||||||
commit('firstName', decoded.firstName)
|
commit('firstName', decoded.firstName)
|
||||||
commit('lastName', decoded.lastName)
|
commit('lastName', decoded.lastName)
|
||||||
commit('description', decoded.description)
|
commit('description', decoded.description)
|
||||||
commit('token', token)
|
|
||||||
},
|
},
|
||||||
logout: ({ commit, state }) => {
|
logout: ({ commit, state }) => {
|
||||||
commit('sessionId', null)
|
commit('token', null)
|
||||||
commit('email', null)
|
commit('email', null)
|
||||||
commit('username', '')
|
commit('username', '')
|
||||||
commit('firstName', '')
|
commit('firstName', '')
|
||||||
commit('lastName', '')
|
commit('lastName', '')
|
||||||
commit('description', '')
|
commit('description', '')
|
||||||
commit('token', null)
|
|
||||||
localStorage.clear()
|
localStorage.clear()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -63,7 +58,6 @@ export const store = new Vuex.Store({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
state: {
|
state: {
|
||||||
sessionId: null,
|
|
||||||
email: '',
|
email: '',
|
||||||
language: null,
|
language: null,
|
||||||
firstName: '',
|
firstName: '',
|
||||||
|
|||||||
@ -1,6 +1,17 @@
|
|||||||
import { mutations, actions } from './store'
|
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
|
const { login, logout } = actions
|
||||||
|
|
||||||
describe('Vuex store', () => {
|
describe('Vuex store', () => {
|
||||||
@ -21,11 +32,11 @@ describe('Vuex store', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sessionId', () => {
|
describe('token', () => {
|
||||||
it('sets the state of sessionId', () => {
|
it('sets the state of token', () => {
|
||||||
const state = { sessionId: null }
|
const state = { token: null }
|
||||||
sessionId(state, '1234')
|
token(state, '1234')
|
||||||
expect(state.sessionId).toEqual('1234')
|
expect(state.token).toEqual('1234')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -66,41 +77,31 @@ describe('Vuex store', () => {
|
|||||||
describe('login', () => {
|
describe('login', () => {
|
||||||
const commit = jest.fn()
|
const commit = jest.fn()
|
||||||
const state = {}
|
const state = {}
|
||||||
const commitedData = {
|
const commitedData = 'token'
|
||||||
sessionId: 1234,
|
|
||||||
user: {
|
|
||||||
email: 'someone@there.is',
|
|
||||||
language: 'en',
|
|
||||||
username: 'user',
|
|
||||||
firstName: 'Peter',
|
|
||||||
lastName: 'Lustig',
|
|
||||||
description: 'Nickelbrille',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
it('calls seven commits', () => {
|
it('calls seven commits', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenCalledTimes(7)
|
expect(commit).toHaveBeenCalledTimes(7)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits sessionId', () => {
|
it('commits token', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', 1234)
|
expect(commit).toHaveBeenNthCalledWith(1, 'token', 'token')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits email', () => {
|
it('commits email', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'someone@there.is')
|
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'user@example.org')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits language', () => {
|
it('commits language', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'en')
|
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'de')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits username', () => {
|
it('commits username', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenNthCalledWith(4, 'username', 'user')
|
expect(commit).toHaveBeenNthCalledWith(4, 'username', 'peter')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits firstName', () => {
|
it('commits firstName', () => {
|
||||||
@ -128,9 +129,9 @@ describe('Vuex store', () => {
|
|||||||
expect(commit).toHaveBeenCalledTimes(6)
|
expect(commit).toHaveBeenCalledTimes(6)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits sessionId', () => {
|
it('commits token', () => {
|
||||||
logout({ commit, state })
|
logout({ commit, state })
|
||||||
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', null)
|
expect(commit).toHaveBeenNthCalledWith(1, 'token', null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits email', () => {
|
it('commits email', () => {
|
||||||
@ -159,7 +160,7 @@ describe('Vuex store', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// how to get this working?
|
// how to get this working?
|
||||||
it.skip('calls sessionStorage.clear()', () => {
|
it.skip('calls localStorage.clear()', () => {
|
||||||
const clearStorageMock = jest.fn()
|
const clearStorageMock = jest.fn()
|
||||||
global.sessionStorage = jest.fn(() => {
|
global.sessionStorage = jest.fn(() => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user