mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix: Pass Language to Admin Interface
This commit is contained in:
parent
6a9d240170
commit
fbf88d6d5b
@ -7,6 +7,7 @@ export const verifyLogin = gql`
|
||||
lastName
|
||||
isAdmin
|
||||
id
|
||||
language
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@ -42,7 +42,7 @@ Vue.use(Toasted, {
|
||||
},
|
||||
})
|
||||
|
||||
addNavigationGuards(router, store, apolloProvider.defaultClient)
|
||||
addNavigationGuards(router, store, apolloProvider.defaultClient, i18n)
|
||||
|
||||
new Vue({
|
||||
moment,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { verifyLogin } from '../graphql/verifyLogin'
|
||||
import CONFIG from '../config'
|
||||
|
||||
const addNavigationGuards = (router, store, apollo) => {
|
||||
const addNavigationGuards = (router, store, apollo, i18n) => {
|
||||
// store token on `authenticate`
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.path === '/authenticate' && to.query && to.query.token) {
|
||||
@ -14,6 +14,7 @@ const addNavigationGuards = (router, store, apollo) => {
|
||||
.then((result) => {
|
||||
const moderator = result.data.verifyLogin
|
||||
if (moderator.isAdmin) {
|
||||
i18n.locale = moderator.language
|
||||
store.commit('moderator', moderator)
|
||||
next({ path: '/' })
|
||||
} else {
|
||||
|
||||
@ -6,9 +6,11 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
isAdmin: true,
|
||||
language: 'de',
|
||||
},
|
||||
},
|
||||
})
|
||||
const i18nLocaleMock = jest.fn()
|
||||
|
||||
const store = {
|
||||
commit: storeCommitMock,
|
||||
@ -21,7 +23,11 @@ const apollo = {
|
||||
query: apolloQueryMock,
|
||||
}
|
||||
|
||||
addNavigationGuards(router, store, apollo)
|
||||
const i18n = {
|
||||
locale: i18nLocaleMock,
|
||||
}
|
||||
|
||||
addNavigationGuards(router, store, apollo, i18n)
|
||||
|
||||
describe('navigation guards', () => {
|
||||
beforeEach(() => {
|
||||
@ -33,19 +39,23 @@ describe('navigation guards', () => {
|
||||
const next = jest.fn()
|
||||
|
||||
describe('with valid token and as admin', () => {
|
||||
beforeEach(() => {
|
||||
navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
|
||||
beforeEach(async () => {
|
||||
await navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
|
||||
})
|
||||
|
||||
it('commits the token to the store', async () => {
|
||||
it('commits the token to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('token', 'valid-token')
|
||||
})
|
||||
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true })
|
||||
it.skip('sets the locale', () => {
|
||||
expect(i18nLocaleMock).toBeCalledWith('de')
|
||||
})
|
||||
|
||||
it('redirects to /', async () => {
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true, language: 'de' })
|
||||
})
|
||||
|
||||
it('redirects to /', () => {
|
||||
expect(next).toBeCalledWith({ path: '/' })
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user