Commit 819260eb authored by Sean Hammond's avatar Sean Hammond

Add test for reason-only registration errors

Add a frontend test for when the server returns an error response with a
"reason" but no "errors" in the JSON-object response body.
parent 31849b3a
......@@ -26,6 +26,7 @@ describe 'h:AuthController', ->
$timeout = null
auth = null
session = null
$controller = null
before ->
angular.module('h', [])
......@@ -41,9 +42,10 @@ describe 'h:AuthController', ->
$provide.value 'formHelpers', mockFormHelpers
return
beforeEach inject ($controller, $rootScope, _$timeout_, _session_) ->
beforeEach inject (_$controller_, $rootScope, _$timeout_, _session_) ->
$scope = $rootScope.$new()
$timeout = _$timeout_
$controller = _$controller_
auth = $controller 'AuthController', {$scope}
session = _session_
sandbox.spy session, 'login'
......@@ -85,6 +87,26 @@ describe 'h:AuthController', ->
{username: 'taken'},
'registration error'
it 'should apply reason-only validation errors from the server', ->
# Make a mock session that returns an error response with a "reason" but
# no "errors" in the JSON object.
reason = 'Argh, crashed! :|'
myMockSession = new MockSession()
myMockSession.register = (data, callback, errback) ->
errback({data: {reason: reason}})
$promise: {finally: sandbox.stub()}
# Get an AuthController object with our mock session.
authCtrl = $controller(
'AuthController', {$scope:$scope, session:myMockSession})
form = {$name: 'register', $valid: true}
authCtrl.submit(form)
assert.calledWith(
mockFormHelpers.applyValidationErrors, form, undefined, reason)
it 'should emit an auth event once authenticated', ->
form =
$name: 'login'
......
Markdown is supported
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