Commit 18166dbe authored by Gergely Ujvari's avatar Gergely Ujvari Committed by ujvari

Add tests for permissions.permits()

parent 878bfeb8
......@@ -40,6 +40,7 @@ describe 'h', ->
assert.equal(perms.delete[0], 'acct:flash@gordon')
assert.equal(perms.admin[0], 'acct:flash@gordon')
describe 'isPublic', ->
it 'isPublic() true if the read permission has group:__world__ in it', ->
annotation = {
permissions: {
......@@ -59,3 +60,30 @@ describe 'h', ->
assert.isFalse(permissions.isPublic(annotation))
annotation.permissions.read = ['one', 'two', 'three']
assert.isFalse(permissions.isPublic(annotation))
describe 'permits', ->
it 'returns true when annotation has no permissions', ->
annotation = {}
assert.isTrue(permissions.permits(null, annotation, null))
it 'returns false for unknown action', ->
annotation = {permissions: permissions.private()}
action = 'Hadouken-ing'
assert.isFalse(permissions.permits(action, annotation, null))
it 'returns true if user different, but permissions has group:__world__', ->
annotation = {permissions: permissions.public()}
annotation.permissions.read.push 'acct:darthsidious@deathstar.emp'
user = 'acct:darthvader@deathstar.emp'
assert.isTrue(permissions.permits('read', annotation, user))
it 'returns true if user is in permissions[action] list', ->
annotation = {permissions: permissions.private()}
user = 'acct:rogerrabbit@toonland'
annotation.permissions.read.push user
assert.isTrue(permissions.permits('read', annotation, user))
it 'returns false if the user name is missing from the list', ->
annotation = {permissions: permissions.private()}
user = 'acct:rogerrabbit@toonland'
assert.isFalse(permissions.permits('read', annotation, user))
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