Merge pull request #950 from gradido/improve-navigation-guard-tests

feat: Improve Test of Navigation Guard of Vue Router
This commit is contained in:
Moriz Wahl 2021-10-11 11:34:25 +02:00 committed by GitHub
commit 144fa5f089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,21 +18,30 @@ describe('navigation guards', () => {
})
describe('publisher ID', () => {
it('commits the pid to the store when present', () => {
router.push({ path: 'login', query: { pid: 42 } })
it('commits the pid to the store when present', async () => {
await router.push({ path: 'register', query: { pid: 42 } })
expect(storeCommitMock).toBeCalledWith('publisherId', '42')
})
it('does not commit the pid when not present', () => {
router.push({ path: 'register' })
it('does not commit the pid when not present', async () => {
await router.push({ path: 'password' })
expect(storeCommitMock).not.toBeCalled()
})
})
describe('authorization', () => {
it.skip('redirects to login when not authorized', async () => {
router.push({ path: 'overview' })
expect(router.history.current.path).toBe('/login')
const navGuard = router.beforeHooks[0]
const next = jest.fn()
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()
})
})
})