mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #950 from gradido/improve-navigation-guard-tests
feat: Improve Test of Navigation Guard of Vue Router
This commit is contained in:
commit
144fa5f089
@ -18,21 +18,30 @@ describe('navigation guards', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('publisher ID', () => {
|
describe('publisher ID', () => {
|
||||||
it('commits the pid to the store when present', () => {
|
it('commits the pid to the store when present', async () => {
|
||||||
router.push({ path: 'login', query: { pid: 42 } })
|
await router.push({ path: 'register', query: { pid: 42 } })
|
||||||
expect(storeCommitMock).toBeCalledWith('publisherId', '42')
|
expect(storeCommitMock).toBeCalledWith('publisherId', '42')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not commit the pid when not present', () => {
|
it('does not commit the pid when not present', async () => {
|
||||||
router.push({ path: 'register' })
|
await router.push({ path: 'password' })
|
||||||
expect(storeCommitMock).not.toBeCalled()
|
expect(storeCommitMock).not.toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('authorization', () => {
|
describe('authorization', () => {
|
||||||
it.skip('redirects to login when not authorized', async () => {
|
const navGuard = router.beforeHooks[0]
|
||||||
router.push({ path: 'overview' })
|
const next = jest.fn()
|
||||||
expect(router.history.current.path).toBe('/login')
|
|
||||||
|
it('redirects to login when not authorized', () => {
|
||||||
|
navGuard({ meta: { requiresAuth: true }, query: {} }, {}, next)
|
||||||
|
expect(next).toBeCalledWith({ path: '/login' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not redirect to login when authorized', () => {
|
||||||
|
store.state.token = 'valid token'
|
||||||
|
navGuard({ meta: { requiresAuth: true }, query: {} }, {}, next)
|
||||||
|
expect(next).toBeCalledWith()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user