Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7bb363b4
Commit
7bb363b4
authored
Aug 07, 2014
by
Aron Carroll
Committed by
Randall Leeds
Aug 21, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hook up response error messages to the account form
parent
cb79e75c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
79 deletions
+75
-79
account-management.coffee
h/static/scripts/controllers/account-management.coffee
+7
-4
account-management-test.coffee
tests/js/controllers/account-management-test.coffee
+68
-75
No files found.
h/static/scripts/controllers/account-management.coffee
View file @
7bb363b4
...
...
@@ -18,11 +18,14 @@ class AccountManagement
identity
.
logout
()
onSuccess
(
form
,
response
)
onError
=
(
form
,
data
)
->
if
400
>=
data
.
status
<
500
util
.
applyValidationErrors
(
form
,
data
.
errors
)
onError
=
(
form
,
response
)
->
if
response
.
status
>=
400
and
response
.
status
<
500
util
.
applyValidationErrors
(
form
,
response
.
data
.
errors
)
else
flash
(
'error'
,
'Sorry, we were unable to perform your request'
)
if
response
.
data
.
flash
flash
(
type
,
msgs
)
for
own
type
,
msgs
of
response
.
data
.
flash
else
flash
(
'error'
,
'Sorry, we were unable to perform your request'
)
# Data for each of the forms
$scope
.
editProfile
=
{}
...
...
tests/js/controllers/account-management-test.coffee
View file @
7bb363b4
...
...
@@ -44,14 +44,17 @@ describe 'h.controllers.AccountManagement', ->
$controller
(
'AccountManagement'
,
{
$scope
:
$scope
})
describe
'.submit'
,
->
it
'updates the password on the backend'
,
->
fakeForm
=
createFakeForm
=
(
overrides
=
{})
->
defaults
=
$name
:
'changePasswordForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'gozer'
password
:
$modelValue
:
'paranormal'
angular
.
extend
(
defaults
,
overrides
)
it
'updates the password on the backend'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
...
...
@@ -61,91 +64,86 @@ describe 'h.controllers.AccountManagement', ->
password
:
'paranormal'
})
it
'displays a flash message on success'
,
->
fakeForm
=
$name
:
'changePasswordForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'gozer'
password
:
$modelValue
:
'paranormal'
it
'clears the fields'
,
->
controller
=
createController
()
$scope
.
changePassword
=
{
pwd
:
'password'
,
password
:
'password'
}
fakeForm
=
createFakeForm
()
# Resolve the request.
editProfilePromise
.
then
.
yields
(
flash
:
{
success
:
[
'Your profile has been updated.'
]
})
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
assert
.
calledWith
(
fakeFlash
,
'success'
,
[
'Your profile has been updated.'
])
assert
.
deepEqual
(
$scope
.
changePassword
,
{})
it
'clears the password field'
,
->
it
'updates the error fields on bad response'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
$scope
.
changePassword
=
{
pwd
:
'password'
,
password
:
'password'
}
# Resolve the request.
editProfilePromise
.
then
.
callArg
1
,
status
:
400
data
:
errors
:
pwd
:
'this is wrong'
fakeForm
=
$name
:
'changePasswordForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'gozer'
password
:
$modelValue
:
'paranormal'
assert
.
calledWith
fakeUtil
.
applyValidationErrors
,
fakeForm
,
pwd
:
'this is wrong'
it
'displays a flash message on success'
,
->
fakeForm
=
createFakeForm
()
# Resolve the request.
editProfilePromise
.
then
.
yields
(
flash
:
{
success
:
[
'Your profile has been updated.'
]
})
$scope
.
submit
(
fakeForm
)
assert
.
deepEqual
(
$scope
.
changePassword
,
{})
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
it
'updates the error fields on bad response'
,
->
fakeForm
=
$name
:
'changePasswordForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'gozer'
password
:
$modelValue
:
'paranormal'
assert
.
calledWith
(
fakeFlash
,
'success'
,
[
'Your profile has been updated.'
])
it
'displays a flash message if a server error occurs'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
# Resolve the request.
editProfilePromise
.
then
.
callArg
1
,
status
:
400
errors
:
pwd
:
'this is wrong'
assert
.
calledWith
fakeUtil
.
applyValidationErrors
,
fakeForm
,
pwd
:
'this is wrong'
status
:
500
data
:
flash
:
error
:
[
'Something bad happened'
]
it
'displays a flash message if a server error occurs'
,
->
fakeForm
=
$name
:
'changePasswordForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'gozer'
password
:
$modelValue
:
'paranormal'
assert
.
calledWith
(
fakeFlash
,
'error'
,
[
'Something bad happened'
])
it
'displays a fallback flash message if none are present'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
submit
(
fakeForm
)
# Resolve the request.
editProfilePromise
.
then
.
callArg
1
,
status
:
500
data
:
{}
assert
.
calledWith
(
fakeFlash
,
'error'
)
assert
.
calledWith
(
fakeFlash
,
'error'
,
'Sorry, we were unable to perform your request'
)
describe
'.delete'
,
->
it
'disables the user account'
,
->
fakeForm
=
createFakeForm
=
(
overrides
=
{})
->
defaults
=
$name
:
'deleteAccountForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'paranormal'
angular
.
extend
(
defaults
,
overrides
)
it
'disables the user account'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
delete
(
fakeForm
)
...
...
@@ -154,12 +152,7 @@ describe 'h.controllers.AccountManagement', ->
pwd
:
'paranormal'
it
'logs the user out of the application'
,
->
fakeForm
=
$name
:
'deleteAccountForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'paranormal'
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
delete
(
fakeForm
)
...
...
@@ -172,12 +165,7 @@ describe 'h.controllers.AccountManagement', ->
it
'clears the password field'
,
->
controller
=
createController
()
fakeForm
=
$name
:
'deleteAccountForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'paranormal'
fakeForm
=
createFakeForm
()
$scope
.
deleteAccount
=
{
pwd
:
''
}
$scope
.
delete
(
fakeForm
)
disableUserPromise
.
then
.
callArg
0
,
...
...
@@ -186,37 +174,42 @@ describe 'h.controllers.AccountManagement', ->
assert
.
deepEqual
(
$scope
.
deleteAccount
,
{})
it
'updates the error fields on bad response'
,
->
fakeForm
=
$name
:
'deleteAccountForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'paranormal'
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
delete
(
fakeForm
)
# Resolve the request.
disableUserPromise
.
then
.
callArg
1
,
status
:
400
errors
:
pwd
:
'this is wrong'
data
:
errors
:
pwd
:
'this is wrong'
assert
.
calledWith
fakeUtil
.
applyValidationErrors
,
fakeForm
,
pwd
:
'this is wrong'
it
'displays a flash message if a server error ocurrs'
,
->
fakeForm
=
$name
:
'deleteAccountForm'
$valid
:
true
$setPristine
:
sandbox
.
spy
()
pwd
:
$modelValue
:
'paranormal'
it
'displays a flash message if a server error occurs'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
delete
(
fakeForm
)
# Resolve the request.
disableUserPromise
.
then
.
callArg
1
,
status
:
500
data
:
flash
:
error
:
[
'Something bad happened'
]
assert
.
calledWith
(
fakeFlash
,
'error'
,
[
'Something bad happened'
])
it
'displays a fallback flash message if none are present'
,
->
fakeForm
=
createFakeForm
()
controller
=
createController
()
$scope
.
delete
(
fakeForm
)
assert
.
calledWith
(
fakeFlash
,
'error'
)
# Resolve the request.
disableUserPromise
.
then
.
callArg
1
,
status
:
500
data
:
{}
assert
.
calledWith
(
fakeFlash
,
'error'
,
'Sorry, we were unable to perform your request'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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