Commit bdd838bf authored by Jean Rabreau's avatar Jean Rabreau
Browse files

refactor&test logout redirection

parent a6c1e21d
......@@ -2,6 +2,7 @@ import i18n from '@/plugins/vue-i18n'
import router from '@/router'
import authority from '@/assets/authAxios'
import { pick, cloneDeep } from 'lodash/fp'
import {setLocation} from '@/store/helpers'
/**
* @typedef {Object} Password
......@@ -244,8 +245,7 @@ const Contrib = {
logOut({commit}, path = ''){
authority.logOut()
commit('LOGIN', false)
const logoutUrl = `${process.env.VUE_APP_AXIOS_BASE_URL}logout?redirect=${appOrigin}${path}`
window.location = logoutUrl
setLocation(`${process.env.VUE_APP_AXIOS_BASE_URL}logout/?redirect=${appOrigin}${path}`)
},
/**
*
......
......@@ -71,10 +71,15 @@ const thumbnailDelete = (rootApi) => ({ commit, dispatch }, objectId) => {
{ root: true },
)
})
};
}
const setLocation = newUrl => {
window.location = newUrl
}
export {
getPaginatedResult,
setLocation,
thumbnailPost,
thumbnailDelete,
THUMBNAILS_UPDATE,
......
......@@ -45,11 +45,6 @@ describe('ProfileMenu', () => {
expect(dispatchStub.calledOnce).to.be.true
expect(dispatchStub.getCall(0).args[0]).to.equal('contrib/logOut')
})
it('should route to log out page', async () => {
await wrapper.vm.onLogOut()
expect(routerStub.calledOnce).to.be.true
expect(routerStub.getCall(0).args[0]).to.eql({name: 'logout'})
})
})
})
})
......@@ -3,6 +3,7 @@ import sinon from 'sinon'
import {cloneDeep} from 'lodash/fp'
import store from '@/store'
import {userInfoInit, userProfileInit} from '@/store/contrib'
import * as helpers from '@/store/helpers'
import i18n from '@/plugins/vue-i18n'
import authority from '@/assets/authAxios'
......@@ -301,21 +302,45 @@ describe('store/contrib', () => {
})
})
describe('logOut', () => {
let logOutStub
const logoutUrl = `${process.env.VUE_APP_AXIOS_BASE_URL}logout/`
const redirectParam = `redirect=${window.location.origin}`
let logOutStub, locationStub
beforeEach(() => {
logOutStub = sinon.stub(authority, 'logOut')
locationStub = sinon.stub(helpers, 'setLocation')
})
afterEach(() => {
logOutStub.restore()
locationStub.restore()
})
it('should call authority logIn method', async () => {
store.dispatch('contrib/logOut')
it('should call authority logOut method', async () => {
await store.dispatch('contrib/logOut')
expect(logOutStub.calledOnce).to.be.true
})
it('should log user out', async () => {
store.dispatch('contrib/logOut')
await store.dispatch('contrib/logOut')
expect(store.state.contrib.isLogged).to.be.false
})
describe('redirection', () => {
beforeEach(async () => {
await store.dispatch('contrib/logOut')
})
it('should set window location to logout api', async () => {
expect(locationStub.calledOnce, 'location changed').to.be.true
expect(locationStub.firstCall.args[0])
.to.match(new RegExp(`^${logoutUrl}`))
})
it('should set a redirection url', () => {
expect(locationStub.firstCall.args[0])
.to.match(new RegExp(`${redirectParam}$`))
})
})
it('should redirect to a given path', async () => {
const desiredPath = '/my/custom/path'
await store.dispatch('contrib/logOut', desiredPath)
expect(locationStub.firstCall.args[0])
.to.match(new RegExp(`${redirectParam}${desiredPath}$`))
})
})
describe('updateProfile', () => {
it('should should call user detail api', async () => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment