Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xpub-faraday
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
xpub
xpub-faraday
Commits
f8dc0b26
Commit
f8dc0b26
authored
7 years ago
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
feat(component-invite): get collection roles
parent
424568c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/component-invite/src/routes/getCollectionUsers.js
+13
-0
13 additions, 0 deletions
packages/component-invite/src/routes/getCollectionUsers.js
packages/component-invite/src/tests/getCollectionUsers.test.js
+45
-5
45 additions, 5 deletions
...ges/component-invite/src/tests/getCollectionUsers.test.js
with
58 additions
and
5 deletions
packages/component-invite/src/routes/getCollectionUsers.js
+
13
−
0
View file @
f8dc0b26
const
helpers
=
require
(
'
../helpers/helpers
'
)
const
teamHelper
=
require
(
'
../helpers/Team
'
)
const
config
=
require
(
'
config
'
)
const
configRoles
=
config
.
get
(
'
roles
'
)
module
.
exports
=
models
=>
async
(
req
,
res
)
=>
{
const
{
role
}
=
req
.
query
if
(
!
helpers
.
checkForUndefinedParams
(
role
))
{
...
...
@@ -8,6 +10,17 @@ module.exports = models => async (req, res) => {
return
}
if
(
!
configRoles
.
collection
.
includes
(
role
))
{
res
.
status
(
400
).
json
({
error
:
`Role
${
role
}
is invalid`
})
return
}
const
reqUser
=
await
models
.
User
.
find
(
req
.
user
)
if
(
!
reqUser
.
editorInChief
)
{
res
.
status
(
400
).
json
({
error
:
'
The request user must be Editor in Chief
'
})
return
}
const
{
collectionId
}
=
req
.
params
try
{
await
models
.
Collection
.
find
(
collectionId
)
...
...
This diff is collapsed.
Click to expand it.
packages/component-invite/src/tests/getCollectionUsers.test.js
+
45
−
5
View file @
f8dc0b26
...
...
@@ -5,7 +5,8 @@ const httpMocks = require('node-mocks-http')
const
fixtures
=
require
(
'
./fixtures/fixtures
'
)
const
Model
=
require
(
'
./helpers/Model
'
)
const
user
=
fixtures
.
users
.
editorInChief
const
{
standardCollection
}
=
fixtures
.
collections
const
{
editorInChief
,
admin
}
=
fixtures
.
users
const
query
=
{
role
:
'
handlingEditor
'
,
}
...
...
@@ -14,7 +15,8 @@ describe('Get collection users route handler', () => {
it
(
'
should return success when the role is correct, the collection exists and the request user is editorInChief
'
,
async
()
=>
{
const
req
=
httpMocks
.
createRequest
()
req
.
query
=
query
req
.
params
.
collectionId
=
'
2c4fb766-a798-4c32-b857-c5d21a2ab331
'
req
.
params
.
collectionId
=
standardCollection
.
id
req
.
user
=
editorInChief
.
id
const
res
=
httpMocks
.
createResponse
()
const
models
=
Model
.
build
()
await
require
(
getCollectionUsersPath
)(
models
)(
req
,
res
)
...
...
@@ -27,13 +29,51 @@ describe('Get collection users route handler', () => {
delete
query
.
role
const
req
=
httpMocks
.
createRequest
()
req
.
query
=
query
req
.
user
=
editorInChief
.
id
const
res
=
httpMocks
.
createResponse
()
const
models
=
Model
.
build
(
user
)
const
models
=
Model
.
build
()
await
require
(
getCollectionUsersPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
400
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
'
Role is required
'
)
query
.
email
=
'
handlingEditor
'
query
.
role
=
'
handlingEditor
'
})
it
(
'
should return an error when the collection does not exist
'
,
async
()
=>
{
const
req
=
httpMocks
.
createRequest
()
req
.
query
=
query
req
.
params
.
collectionId
=
'
invalid-id
'
req
.
user
=
editorInChief
.
id
const
res
=
httpMocks
.
createResponse
()
const
models
=
Model
.
build
()
await
require
(
getCollectionUsersPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
404
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
'
collection not found
'
)
})
it
(
'
should return an error when the role is invalid
'
,
async
()
=>
{
query
.
role
=
'
invalidRole
'
const
req
=
httpMocks
.
createRequest
()
req
.
query
=
query
req
.
params
.
collectionId
=
standardCollection
.
id
req
.
user
=
editorInChief
.
id
const
res
=
httpMocks
.
createResponse
()
const
models
=
Model
.
build
()
await
require
(
getCollectionUsersPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
400
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
`Role
${
query
.
role
}
is invalid`
)
query
.
role
=
'
handlingEditor
'
})
it
(
'
should return an error when the request user is not editorInChief
'
,
async
()
=>
{
const
req
=
httpMocks
.
createRequest
()
req
.
query
=
query
req
.
params
.
collectionId
=
standardCollection
.
id
req
.
user
=
admin
.
id
const
res
=
httpMocks
.
createResponse
()
const
models
=
Model
.
build
()
await
require
(
getCollectionUsersPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
400
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
'
The request user must be Editor in Chief
'
)
})
})
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment