Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
40b5dbed
Commit
40b5dbed
authored
Dec 16, 2014
by
Gergely Ujvari
Committed by
ujvari
Jan 15, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for permissions service
parent
3e0b3e16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
12 deletions
+95
-12
privacy-test.coffee
tests/js/directives/privacy-test.coffee
+34
-12
permissions-service-test.coffee
tests/js/permissions-service-test.coffee
+61
-0
No files found.
tests/js/directives/privacy-test.coffee
View file @
40b5dbed
...
...
@@ -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
tests/js/permissions-service-test.coffee
0 → 100644
View file @
40b5dbed
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
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment