Commit ba6c10fa authored by Gergely Ujvari's avatar Gergely Ujvari

Fix auth related tests

parent 0a6aef27
......@@ -24,7 +24,7 @@ describe 'h.account.AccountController', ->
fakeFormHelpers =
applyValidationErrors: sandbox.spy()
fakeAuth =
getPersona: (-> 'egon@columbia.edu')
user: 'egon@columbia.edu'
$filterProvider.register 'persona', ->
sandbox.stub().returns('STUBBED_PERSONA_FILTER')
......
......@@ -4,10 +4,10 @@ sinon.assert.expose assert, prefix: null
describe 'h', ->
$scope = null
fakeAuth = null
fakeIdentity = null
fakeLocation = null
fakeParams = null
fakeStreamer = null
fakeIdentity = null
sandbox = null
beforeEach module('h')
......@@ -15,18 +15,6 @@ describe 'h', ->
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAuth = {
user: null
getInitialUser: ->
then: (resolve, reject) ->
resolve()
}
fakeIdentity = {
watch: sandbox.spy()
request: sandbox.spy()
}
fakeAnnotator = {
plugins: {
Auth: {withToken: sandbox.spy()}
......@@ -36,6 +24,15 @@ describe 'h', ->
addPlugin: sandbox.spy()
}
fakeAuth = {
user: null
}
fakeIdentity = {
watch: sandbox.spy()
request: sandbox.spy()
}
fakeLocation = {
search: sandbox.stub().returns({})
}
......@@ -66,7 +63,8 @@ describe 'h', ->
$controller('AppController', {$scope: $scope})
it 'does not show login form for logged in users', ->
app = createController()
createController()
$scope.$digest()
assert.isFalse($scope.dialog.visible)
describe 'AnnotationViewerController', ->
......
......@@ -13,16 +13,25 @@ describe 'h', ->
fakeAnnotator = {
plugins: {
Auth: {withToken: sandbox.spy()}
Auth:{
withToken: sandbox.spy()
destroy: sandbox.spy()
element: {removeData: sandbox.spy()}
}
Permissions: {
destroy: sandbox.spy()
setUser: sandbox.spy()
}
}
options: {}
socialView: {name: 'none'}
addPlugin: sandbox.spy()
}
fakeIdentity = {
fakeIdentity ={
watch: sandbox.spy()
request: sandbox.spy()
}
$provide.value 'annotator', fakeAnnotator
......@@ -42,8 +51,29 @@ describe 'h', ->
it 'watches the identity service for identity change events', ->
assert.calledOnce(fakeIdentity.watch)
it 'sets the persona to null when the identity has been checked', ->
{onlogin, onlogout, onready} = fakeIdentity.watch.args[0][0]
it 'sets the user to null when the identity has been checked', ->
{onready} = fakeIdentity.watch.args[0][0]
onready()
assert.isNull(auth.user)
it 'sets the Permissions plugin and sets auth.user at login', ->
{onlogin} = fakeIdentity.watch.args[0][0]
onlogin('test-assertion')
fakeToken = { userId: 'acct:hey@joe'}
userSetter = fakeAnnotator.plugins.Auth.withToken.args[0][0]
userSetter(fakeToken)
assert.equal(auth.user, 'acct:hey@joe')
secondPlugin = fakeAnnotator.addPlugin.args[1]
assert.equal(secondPlugin[0], 'Permissions')
it 'destroys the plugins at logout and sets auth.user to null', ->
{onlogout} = fakeIdentity.watch.args[0][0]
auth.user = 'acct:hey@joe'
authPlugin = fakeAnnotator.plugins.Auth
permissionsPlugin = fakeAnnotator.plugins.Permissions
onlogout()
assert.called(authPlugin.destroy)
assert.called(permissionsPlugin.destroy)
assert.equal(auth.user, null)
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