Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
community
pount
pount-front
Commits
bdd838bf
Commit
bdd838bf
authored
Sep 10, 2021
by
Jean Rabreau
Browse files
✅
refactor&test logout redirection
parent
a6c1e21d
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/store/contrib.js
View file @
bdd838bf
...
...
@@ -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
}
`
)
},
/**
*
...
...
src/store/helpers.js
View file @
bdd838bf
...
...
@@ -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
,
...
...
tests/unit/components/menu/ProfileMenu.spec.js
View file @
bdd838bf
...
...
@@ -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
'
})
})
})
})
})
tests/unit/store/contrib.spec.js
View file @
bdd838bf
...
...
@@ -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 log
In
method
'
,
async
()
=>
{
store
.
dispatch
(
'
contrib/logOut
'
)
it
(
'
should call authority log
Out
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
()
=>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment