mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
Test guards with roles array for verfiyLogin.
This commit is contained in:
parent
8b2d07c0af
commit
bed2b86ea5
@ -5,7 +5,7 @@ const storeCommitMock = jest.fn()
|
||||
const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
isAdmin: true,
|
||||
roles: ['ADMIN'],
|
||||
language: 'de',
|
||||
},
|
||||
},
|
||||
@ -52,7 +52,12 @@ describe('navigation guards', () => {
|
||||
})
|
||||
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true, language: 'de' })
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', {
|
||||
roles: ['ADMIN'],
|
||||
isAdmin: true,
|
||||
isModerator: false,
|
||||
language: 'de',
|
||||
})
|
||||
})
|
||||
|
||||
it('redirects to /', () => {
|
||||
@ -60,12 +65,49 @@ describe('navigation guards', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with valid token and not as admin', () => {
|
||||
describe('with valid token and as moderator', () => {
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
apolloQueryMock.mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
roles: ['MODERATOR'],
|
||||
language: 'de',
|
||||
},
|
||||
},
|
||||
})
|
||||
await navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
|
||||
})
|
||||
|
||||
it('commits the token to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('token', 'valid-token')
|
||||
})
|
||||
|
||||
it.skip('sets the locale', () => {
|
||||
expect(i18nLocaleMock).toBeCalledWith('de')
|
||||
})
|
||||
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', {
|
||||
roles: ['MODERATOR'],
|
||||
isAdmin: false,
|
||||
isModerator: true,
|
||||
language: 'de',
|
||||
})
|
||||
})
|
||||
|
||||
it('redirects to /', () => {
|
||||
expect(next).toBeCalledWith({ path: '/' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('with valid token and no roles', () => {
|
||||
beforeEach(() => {
|
||||
apolloQueryMock.mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
isAdmin: false,
|
||||
roles: [],
|
||||
language: 'de',
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -128,17 +170,24 @@ describe('navigation guards', () => {
|
||||
expect(next).toBeCalledWith({ path: '/not-found' })
|
||||
})
|
||||
|
||||
it('redirects to not found with token in store and not moderator', () => {
|
||||
it('redirects to not found with token in store and not admin or moderator', () => {
|
||||
store.state.token = 'valid token'
|
||||
navGuard({ path: '/' }, {}, next)
|
||||
expect(next).toBeCalledWith({ path: '/not-found' })
|
||||
})
|
||||
|
||||
it('does not redirect with token in store and as moderator', () => {
|
||||
it('does not redirect with token in store and as admin', () => {
|
||||
store.state.token = 'valid token'
|
||||
store.state.moderator = { isAdmin: true }
|
||||
navGuard({ path: '/' }, {}, next)
|
||||
expect(next).toBeCalledWith()
|
||||
})
|
||||
|
||||
it('does not redirect with token in store and as moderator', () => {
|
||||
store.state.token = 'valid token'
|
||||
store.state.moderator = { isModerator: true }
|
||||
navGuard({ path: '/' }, {}, next)
|
||||
expect(next).toBeCalledWith()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user