Commit 40b5dbed authored by Gergely Ujvari's avatar Gergely Ujvari Committed by ujvari

Tests for permissions service

parent 3e0b3e16
......@@ -16,14 +16,22 @@ describe 'h.directives.privacy', ->
beforeEach module('h.templates')
describe 'memory fallback', ->
fakeAuth = null
fakeWindow = null
sandbox = null
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAuth = {
user: 'acct:angry.joe@texas.com'
}
fakeWindow = {
localStorage: undefined
}
$provide.value 'auth', fakeAuth
$provide.value '$window', fakeWindow
return
......@@ -55,6 +63,22 @@ describe 'h.directives.privacy', ->
assert.equal readPermissions, 'group:__world__'
describe 'has localStorage', ->
sandbox = null
fakeAuth = null
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAuth = {
user: 'acct:angry.joe@texas.com'
}
$provide.value 'auth', fakeAuth
return
afterEach ->
sandbox.restore()
beforeEach inject (_$compile_, _$rootScope_, _$injector_, _$window_) ->
$compile = _$compile_
$scope = _$rootScope_.$new()
......@@ -129,32 +153,30 @@ describe 'h.directives.privacy', ->
beforeEach ->
$scope.permissions = {read: []}
it 'fills the permissions fields with the given user name', ->
it 'fills the permissions fields with the auth.user name', ->
store.setItem VISIBILITY_KEY, VISIBILITY_PRIVATE
$element = $compile('<privacy ng-model="permissions" user="acct:user@example.com">')($scope)
$element = $compile('<privacy ng-model="permissions">')($scope)
$scope.$digest()
user = "acct:user@example.com"
readPermissions = $scope.permissions.read[0]
updatePermissions = $scope.permissions.update[0]
deletePermissions = $scope.permissions.delete[0]
adminPermissions = $scope.permissions.admin[0]
assert.equal readPermissions, user
assert.equal updatePermissions, user
assert.equal deletePermissions, user
assert.equal adminPermissions, user
assert.equal readPermissions, fakeAuth.user
assert.equal updatePermissions, fakeAuth.user
assert.equal deletePermissions, fakeAuth.user
assert.equal adminPermissions, fakeAuth.user
it 'puts group_world into the read permissions for public visibility', ->
store.setItem VISIBILITY_KEY, VISIBILITY_PUBLIC
$element = $compile('<privacy ng-model="permissions" user="acct:user@example.com">')($scope)
$element = $compile('<privacy ng-model="permissions">')($scope)
$scope.$digest()
user = "acct:user@example.com"
readPermissions = $scope.permissions.read[0]
updatePermissions = $scope.permissions.update[0]
deletePermissions = $scope.permissions.delete[0]
adminPermissions = $scope.permissions.admin[0]
assert.equal readPermissions, 'group:__world__'
assert.equal updatePermissions, user
assert.equal deletePermissions, user
assert.equal adminPermissions, user
assert.equal updatePermissions, fakeAuth.user
assert.equal deletePermissions, fakeAuth.user
assert.equal adminPermissions, fakeAuth.user
assert = chai.assert
sinon.assert.expose assert, prefix: null
describe 'h', ->
sandbox = null
fakeAuth = null
beforeEach module('h')
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAuth = {
user: 'acct:flash@gordon'
}
$provide.value 'auth', fakeAuth
return
afterEach ->
sandbox.restore()
describe 'permissions service', ->
permissions = null
beforeEach inject (_permissions_) ->
permissions = _permissions_
it 'private call fills all permissions with auth.user', ->
perms = permissions.private()
assert.equal(perms.read[0], 'acct:flash@gordon')
assert.equal(perms.update[0], 'acct:flash@gordon')
assert.equal(perms.delete[0], 'acct:flash@gordon')
assert.equal(perms.admin[0], 'acct:flash@gordon')
it 'public call fills the read property with group:__world__', ->
perms = permissions.public()
assert.equal(perms.read[0], 'group:__world__')
assert.equal(perms.update[0], 'acct:flash@gordon')
assert.equal(perms.delete[0], 'acct:flash@gordon')
assert.equal(perms.admin[0], 'acct:flash@gordon')
it 'isPublic() true if the read permission has group:__world__ in it', ->
annotation = {
permissions: {
read: ['group:__world__', 'acct:angry@birds.com']
}
}
assert.isTrue(permissions.isPublic(annotation))
it 'isPublic() false otherwise', ->
annotation = {
permissions: {
read: ['acct:angry@birds.com']
}
}
assert.isFalse(permissions.isPublic(annotation))
annotation.permissions.read = []
assert.isFalse(permissions.isPublic(annotation))
annotation.permissions.read = ['one', 'two', 'three']
assert.isFalse(permissions.isPublic(annotation))
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