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
b7cc0dd5
Commit
b7cc0dd5
authored
7 years ago
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
tests(components-invite): add some tests for post assignation
parent
6d64770d
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/postAssignation.js
+1
-1
1 addition, 1 deletion
packages/component-invite/src/routes/postAssignation.js
packages/component-invite/src/tests/postAssignation.test.js
+75
-3
75 additions, 3 deletions
packages/component-invite/src/tests/postAssignation.test.js
with
76 additions
and
4 deletions
packages/component-invite/src/routes/postAssignation.js
+
1
−
1
View file @
b7cc0dd5
...
...
@@ -45,7 +45,7 @@ module.exports = models => async (req, res) => {
await
models
.
Collection
.
find
(
collectionId
)
// TODO: create a team and add the team id to the user's teams array
user
.
assignation
.
hasAnswer
=
true
if
(
accept
)
{
if
(
accept
===
true
)
{
user
.
assignation
.
isAccepted
=
true
}
await
user
.
save
()
...
...
This diff is collapsed.
Click to expand it.
packages/component-invite/src/tests/postAssignation.test.js
+
75
−
3
View file @
b7cc0dd5
...
...
@@ -4,6 +4,7 @@ process.env.SUPPRESS_NO_CONFIG_WARNING = true
const
httpMocks
=
require
(
'
node-mocks-http
'
)
const
fixtures
=
require
(
'
./fixtures/fixtures
'
)
const
UserMock
=
require
(
'
./mocks/User
'
)
const
cloneDeep
=
require
(
'
lodash/cloneDeep
'
)
jest
.
mock
(
'
pubsweet-component-mail-service
'
,
()
=>
({
setupAssignEmail
:
jest
.
fn
(),
...
...
@@ -38,6 +39,7 @@ const { standardCollection } = fixtures.collections
const
postAssignationPath
=
'
../routes/postAssignation
'
describe
(
'
Post assignation route handler
'
,
()
=>
{
it
(
'
should return success when the handling editor accepts work on a collection
'
,
async
()
=>
{
const
acceptingHE
=
cloneDeep
(
handlingEditor
)
const
body
=
{
type
:
'
handlingEditor
'
,
accept
:
true
,
...
...
@@ -45,13 +47,83 @@ describe('Post assignation route handler', () => {
const
req
=
httpMocks
.
createRequest
({
body
,
})
req
.
user
=
acceptingHE
const
res
=
httpMocks
.
createResponse
()
const
models
=
buildModels
(
standardCollection
,
acceptingHE
)
await
require
(
postAssignationPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
204
)
expect
(
acceptingHE
.
assignation
.
hasAnswer
).
toBeTruthy
()
expect
(
acceptingHE
.
assignation
.
isAccepted
).
toBeTruthy
()
})
it
(
'
should return success when the handling editor refuses work on a collection
'
,
async
()
=>
{
const
refusingHE
=
cloneDeep
(
handlingEditor
)
const
body
=
{
type
:
'
handlingEditor
'
,
accept
:
false
,
}
const
req
=
httpMocks
.
createRequest
({
body
,
})
req
.
user
=
refusingHE
const
res
=
httpMocks
.
createResponse
()
const
models
=
buildModels
(
standardCollection
,
refusingHE
)
await
require
(
postAssignationPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
204
)
expect
(
refusingHE
.
assignation
.
hasAnswer
).
toBeTruthy
()
expect
(
refusingHE
.
assignation
.
isAccepted
).
toBeFalsy
()
})
it
(
'
should return an error params are missing
'
,
async
()
=>
{
const
body
=
{
type
:
'
handlingEditor
'
,
}
const
req
=
httpMocks
.
createRequest
({
body
,
})
req
.
user
=
handlingEditor
const
res
=
httpMocks
.
createResponse
()
const
models
=
buildModels
(
standardCollection
,
handlingEditor
)
await
require
(
postAssignationPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
204
)
expect
(
handlingEditor
.
assignation
.
hasAnswer
).
toBeTruthy
()
expect
(
handlingEditor
.
assignation
.
isAccepted
).
toBeTruthy
()
expect
(
res
.
statusCode
).
toBe
(
400
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
'
Type and accept are required
'
)
})
it
(
'
should return an error if the collection id does not exists
'
,
async
()
=>
{
const
body
=
{
type
:
'
handlingEditor
'
,
accept
:
false
,
}
const
req
=
httpMocks
.
createRequest
({
body
,
})
req
.
user
=
handlingEditor
const
res
=
httpMocks
.
createResponse
()
const
models
=
buildModels
(
notFoundError
,
handlingEditor
)
await
require
(
postAssignationPath
)(
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 request user does not have any assignation
'
,
async
()
=>
{
const
noAssignationEditor
=
cloneDeep
(
handlingEditor
)
const
body
=
{
type
:
'
handlingEditor
'
,
accept
:
false
,
}
const
req
=
httpMocks
.
createRequest
({
body
,
})
delete
noAssignationEditor
.
assignation
req
.
user
=
noAssignationEditor
const
res
=
httpMocks
.
createResponse
()
const
models
=
buildModels
(
standardCollection
,
noAssignationEditor
)
await
require
(
postAssignationPath
)(
models
)(
req
,
res
)
expect
(
res
.
statusCode
).
toBe
(
400
)
const
data
=
JSON
.
parse
(
res
.
_getData
())
expect
(
data
.
error
).
toEqual
(
'
The user has no assignation
'
)
})
})
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