Commit 4bcb73e4 authored by Aron Carroll's avatar Aron Carroll

Merge pull request #1903 from hypothesis/no-account-module

Eliminate the explicit account module.
parents 90c39fef 11e809f7
......@@ -87,5 +87,5 @@ class AccountController
angular.module('h.account')
angular.module('h')
.controller('AccountController', AccountController)
imports = [
'ngRoute'
'h.identity'
'h.helpers'
'h.session'
]
AUTH_SESSION_ACTIONS = [
'login'
'logout'
......@@ -126,6 +119,7 @@ configure = [
]
angular.module('h.account', imports, configure)
angular.module('h')
.config(configure)
.controller('AuthAppController', AuthAppController)
.controller('AuthPageController', AuthPageController)
......@@ -53,5 +53,5 @@ class AuthController
, 300000
angular.module('h.account')
angular.module('h')
.controller('AuthController', AuthController)
......@@ -3,7 +3,6 @@ imports = [
'ngRoute'
'ngSanitize'
'ngTagsInput'
'h.account'
'h.helpers'
'h.identity'
'h.session'
......
......@@ -2,7 +2,7 @@ assert = chai.assert
sinon.assert.expose assert, prefix: null
sandbox = sinon.sandbox.create()
describe 'h.account.AccountController', ->
describe 'AccountController', ->
$scope = null
fakeFlash = null
fakeSession = null
......@@ -14,7 +14,7 @@ describe 'h.account.AccountController', ->
profilePromise = null
createController = null
beforeEach module('h.account')
beforeEach module('h')
beforeEach module ($provide, $filterProvider) ->
fakeSession = {}
......
......@@ -19,8 +19,13 @@ class MockSession
mockFlash = sandbox.spy()
mockFormHelpers = applyValidationErrors: sandbox.spy()
describe 'h.account', ->
beforeEach module('h.account')
describe 'AuthController', ->
$scope = null
$timeout = null
auth = null
session = null
beforeEach module('h')
beforeEach module('h.templates')
beforeEach module ($provide) ->
......@@ -30,95 +35,89 @@ describe 'h.account', ->
$provide.value 'formHelpers', mockFormHelpers
return
beforeEach inject ($controller, $rootScope, _$timeout_, _session_) ->
$scope = $rootScope.$new()
$timeout = _$timeout_
auth = $controller 'AuthController', {$scope}
session = _session_
sandbox.spy session, 'login'
afterEach ->
sandbox.restore()
describe 'AuthController', ->
$scope = null
$timeout = null
auth = null
session = null
beforeEach inject ($controller, $rootScope, _$timeout_, _session_) ->
$scope = $rootScope.$new()
$timeout = _$timeout_
auth = $controller 'AuthController', {$scope}
session = _session_
sandbox.spy session, 'login'
describe '#submit()', ->
it 'should call session methods on submit', ->
auth.submit
$name: 'login'
$valid: true
$setValidity: sandbox.stub()
assert.called session.login
describe '#submit()', ->
it 'should call session methods on submit', ->
it 'should do nothing when the form is invalid', ->
auth.submit
$name: 'login'
$valid: false
$setValidity: sandbox.stub()
assert.notCalled session.login
auth.submit
$name: 'login'
$valid: true
$setValidity: sandbox.stub()
it 'should apply validation errors on submit', ->
form =
$name: 'register'
$valid: true
$setValidity: sandbox.stub()
username:
$setValidity: sandbox.stub()
email:
$setValidity: sandbox.stub()
assert.called session.login
auth.submit(form)
it 'should do nothing when the form is invalid', ->
auth.submit
$name: 'login'
$valid: false
$setValidity: sandbox.stub()
assert.calledWith mockFormHelpers.applyValidationErrors, form,
{username: 'taken'},
'registration error'
assert.notCalled session.login
it 'should emit an auth event once authenticated', ->
form =
$name: 'login'
$valid: true
it 'should apply validation errors on submit', ->
form =
$name: 'register'
$valid: true
$setValidity: sandbox.stub()
username:
$setValidity: sandbox.stub()
email:
$setValidity: sandbox.stub()
sandbox.spy $scope, '$emit'
auth.submit(form)
assert.calledWith $scope.$emit, 'auth', null, userid: 'alice'
it 'should emit an auth event if destroyed before authentication', ->
sandbox.spy $scope, '$emit'
$scope.$destroy()
assert.calledWith $scope.$emit, 'auth', 'cancel'
describe 'timeout', ->
it 'should happen after a period of inactivity', ->
sandbox.spy $scope, '$broadcast'
$scope.form = $setPristine: sandbox.stub()
$scope.model =
username: 'test'
email: 'test@example.com'
password: 'secret'
code: '1234'
$scope.$digest()
assert.called $timeout
$timeout.lastCall.args[0]()
assert.called $scope.form.$setPristine, 'the form is pristine'
assert.deepEqual $scope.model, {}, 'the model is erased'
assert.called mockFlash, 'a notification is flashed'
it 'should not happen if the model is empty', ->
$scope.model = undefined
$scope.$digest()
assert.notCalled $timeout
$scope.model = {}
$scope.$digest()
assert.notCalled $timeout
auth.submit(form)
assert.calledWith mockFormHelpers.applyValidationErrors, form,
{username: 'taken'},
'registration error'
it 'should emit an auth event once authenticated', ->
form =
$name: 'login'
$valid: true
$setValidity: sandbox.stub()
sandbox.spy $scope, '$emit'
auth.submit(form)
assert.calledWith $scope.$emit, 'auth', null, userid: 'alice'
it 'should emit an auth event if destroyed before authentication', ->
sandbox.spy $scope, '$emit'
$scope.$destroy()
assert.calledWith $scope.$emit, 'auth', 'cancel'
describe 'timeout', ->
it 'should happen after a period of inactivity', ->
sandbox.spy $scope, '$broadcast'
$scope.form = $setPristine: sandbox.stub()
$scope.model =
username: 'test'
email: 'test@example.com'
password: 'secret'
code: '1234'
$scope.$digest()
assert.called $timeout
$timeout.lastCall.args[0]()
assert.called $scope.form.$setPristine, 'the form is pristine'
assert.deepEqual $scope.model, {}, 'the model is erased'
assert.called mockFlash, 'a notification is flashed'
it 'should not happen if the model is empty', ->
$scope.model = undefined
$scope.$digest()
assert.notCalled $timeout
$scope.model = {}
$scope.$digest()
assert.notCalled $timeout
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