Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wxcafé
funkwhale
Commits
90611ffa
Verified
Commit
90611ffa
authored
7 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Added missing ajax unit tests
parent
736caa39
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
front/src/store/auth.js
+1
-2
1 addition, 2 deletions
front/src/store/auth.js
front/test/unit/specs/store/auth.spec.js
+92
-0
92 additions, 0 deletions
front/test/unit/specs/store/auth.spec.js
front/test/unit/utils.js
+2
-2
2 additions, 2 deletions
front/test/unit/utils.js
with
95 additions
and
4 deletions
front/src/store/auth.js
+
1
−
2
View file @
90611ffa
...
...
@@ -39,7 +39,6 @@ export default {
state
.
token
=
value
if
(
value
)
{
state
.
tokenData
=
jwtDecode
(
value
)
console
.
log
(
state
.
tokenData
)
}
else
{
state
.
tokenData
=
{}
}
...
...
@@ -50,7 +49,7 @@ export default {
},
actions
:
{
// Send a request to the login URL and save the returned JWT
login
({
commit
,
dispatch
,
state
},
{
next
,
credentials
,
onError
})
{
login
({
commit
,
dispatch
},
{
next
,
credentials
,
onError
})
{
return
axios
.
post
(
'
token/
'
,
credentials
).
then
(
response
=>
{
logger
.
default
.
info
(
'
Successfully logged in as
'
,
credentials
.
username
)
commit
(
'
token
'
,
response
.
data
.
token
)
...
...
This diff is collapsed.
Click to expand it.
front/test/unit/specs/store/auth.spec.js
+
92
−
0
View file @
90611ffa
var
sinon
=
require
(
'
sinon
'
)
import
moxios
from
'
moxios
'
import
store
from
'
@/store/auth
'
import
{
testAction
}
from
'
../../utils
'
describe
(
'
store/auth
'
,
()
=>
{
var
sandbox
beforeEach
(
function
()
{
sandbox
=
sinon
.
sandbox
.
create
()
moxios
.
install
()
})
afterEach
(
function
()
{
sandbox
.
restore
()
moxios
.
uninstall
()
})
describe
(
'
mutations
'
,
()
=>
{
it
(
'
profile
'
,
()
=>
{
const
state
=
{}
...
...
@@ -104,5 +117,84 @@ describe('store/auth', () => {
]
},
done
)
})
it
(
'
login success
'
,
(
done
)
=>
{
moxios
.
stubRequest
(
'
token/
'
,
{
status
:
200
,
response
:
{
token
:
'
test
'
}
})
const
credentials
=
{
username
:
'
bob
'
}
testAction
({
action
:
store
.
actions
.
login
,
payload
:
{
credentials
:
credentials
},
expectedMutations
:
[
{
type
:
'
token
'
,
payload
:
'
test
'
},
{
type
:
'
username
'
,
payload
:
'
bob
'
},
{
type
:
'
authenticated
'
,
payload
:
true
}
],
expectedActions
:
[
{
type
:
'
fetchProfile
'
}
]
},
done
)
})
it
(
'
login error
'
,
(
done
)
=>
{
moxios
.
stubRequest
(
'
token/
'
,
{
status
:
500
,
response
:
{
token
:
'
test
'
}
})
const
credentials
=
{
username
:
'
bob
'
}
let
spy
=
sandbox
.
spy
()
testAction
({
action
:
store
.
actions
.
login
,
payload
:
{
credentials
:
credentials
,
onError
:
spy
}
},
()
=>
{
expect
(
spy
.
calledOnce
).
to
.
equal
(
true
)
done
()
})
})
it
(
'
fetchProfile
'
,
(
done
)
=>
{
const
profile
=
{
username
:
'
bob
'
,
permissions
:
{
admin
:
{
status
:
true
}
}
}
moxios
.
stubRequest
(
'
users/users/me/
'
,
{
status
:
200
,
response
:
profile
})
testAction
({
action
:
store
.
actions
.
fetchProfile
,
expectedMutations
:
[
{
type
:
'
profile
'
,
payload
:
profile
},
{
type
:
'
permission
'
,
payload
:
{
key
:
'
admin
'
,
status
:
true
}
}
],
expectedActions
:
[
{
type
:
'
favorites/fetch
'
,
payload
:
null
,
options
:
{
root
:
true
}
}
]
},
done
)
})
it
(
'
refreshToken
'
,
(
done
)
=>
{
moxios
.
stubRequest
(
'
token/refresh/
'
,
{
status
:
200
,
response
:
{
token
:
'
newtoken
'
}
})
testAction
({
action
:
store
.
actions
.
refreshToken
,
params
:
{
state
:
{
token
:
'
oldtoken
'
}},
expectedMutations
:
[
{
type
:
'
token
'
,
payload
:
'
newtoken
'
}
]
},
done
)
})
})
})
This diff is collapsed.
Click to expand it.
front/test/unit/utils.js
+
2
−
2
View file @
90611ffa
...
...
@@ -66,8 +66,8 @@ export const testAction = ({action, payload, params, expectedMutations, expected
// call the action with mocked store and arguments
let
promise
=
action
({
commit
,
dispatch
,
...
params
},
payload
)
if
(
promise
)
{
promise
.
then
(
end
)
return
promise
.
then
(
end
)
}
else
{
end
()
return
end
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment