Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xpub-elife
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review 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-elife
Commits
b0bc1dd0
Commit
b0bc1dd0
authored
6 years ago
by
Mihail Dunaev
Browse files
Options
Downloads
Patches
Plain Diff
chore(submission): use json-to-graphql-query in tests to make code look nicer
re #52
parent
67c13324
No related branches found
No related tags found
1 merge request
!29
Get current ms
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/submission/definitions.test.js
+85
-125
85 additions, 125 deletions
server/submission/definitions.test.js
server/submission/package.json
+1
-0
1 addition, 0 deletions
server/submission/package.json
yarn.lock
+5
-1
5 additions, 1 deletion
yarn.lock
with
91 additions
and
126 deletions
server/submission/definitions.test.js
+
85
−
125
View file @
b0bc1dd0
...
...
@@ -5,6 +5,7 @@ const User = require('pubsweet-server/src/models/User')
const
authentication
=
require
(
'
pubsweet-server/src/authentication
'
)
const
{
save
,
select
,
selectId
}
=
require
(
'
../db-helpers/
'
)
const
_
=
require
(
'
lodash
'
)
const
{
jsonToGraphQLQuery
}
=
require
(
'
json-to-graphql-query
'
)
const
userData
=
{
username
:
'
testuser
'
,
...
...
@@ -54,24 +55,27 @@ describe('Submission', () => {
await
save
(
expectedManuscript
)
// query to get it
const
query
=
`
query CurrentSubmission {
currentSubmission {
title
source
submissionMeta {
stage
author {
firstName
lastName
email
institution
}
}
}
}`
const
query
=
{
query
:
{
currentSubmission
:
{
title
:
true
,
source
:
true
,
submissionMeta
:
{
stage
:
true
,
author
:
{
firstName
:
true
,
lastName
:
true
,
email
:
true
,
institution
:
true
,
},
},
},
},
}
const
graphqlQuery
=
jsonToGraphQLQuery
(
query
,
{
pretty
:
true
})
const
{
body
}
=
await
request
(
query
)
// const { body } = await request(query)
const
{
body
}
=
await
request
(
graphqlQuery
)
expect
(
body
.
errors
).
toBeUndefined
()
// get rid of createdBy
...
...
@@ -80,24 +84,26 @@ describe('Submission', () => {
})
it
(
'
Returns empty object when there are no manuscripts in the db
'
,
async
()
=>
{
const
query
=
`
query CurrentSubmission {
currentSubmission {
id
title
source
submissionMeta {
stage
author {
firstName
lastName
email
institution
}
}
}
}`
const
{
body
}
=
await
request
(
query
)
const
query
=
{
query
:
{
currentSubmission
:
{
id
:
true
,
title
:
true
,
source
:
true
,
submissionMeta
:
{
stage
:
true
,
author
:
{
firstName
:
true
,
lastName
:
true
,
email
:
true
,
institution
:
true
,
},
},
},
},
}
const
graphqlQuery
=
jsonToGraphQLQuery
(
query
,
{
pretty
:
true
})
const
{
body
}
=
await
request
(
graphqlQuery
)
expect
(
body
.
errors
).
toBeUndefined
()
expect
(
body
.
data
.
currentSubmission
).
toBe
(
null
)
})
...
...
@@ -133,39 +139,42 @@ describe('Submission', () => {
},
})
const
query
=
`
query CurrentSubmission {
currentSubmission {
id
title
source
submissionMeta {
stage
author {
firstName
lastName
email
institution
}
}
}
}`
const
query
=
{
query
:
{
currentSubmission
:
{
id
:
true
,
title
:
true
,
source
:
true
,
submissionMeta
:
{
stage
:
true
,
author
:
{
firstName
:
true
,
lastName
:
true
,
email
:
true
,
institution
:
true
,
},
},
},
},
}
const
graphqlQuery
=
jsonToGraphQLQuery
(
query
,
{
pretty
:
true
})
// null for current user
const
{
body
}
=
await
request
(
q
uery
)
const
{
body
}
=
await
request
(
graphqlQ
uery
)
expect
(
body
.
errors
).
toBeUndefined
()
expect
(
body
.
data
.
currentSubmission
).
toBe
(
null
)
})
it
(
'
createSubmission adds new manuscript to the db for current user with stage INITIAL
'
,
async
()
=>
{
const
query
=
`
mutation CreateSubmission {
createSubmission {
id
}
}
`
await
request
(
query
)
const
query
=
{
mutation
:
{
createSubmission
:
{
id
:
true
,
},
},
}
const
graphqlQuery
=
jsonToGraphQLQuery
(
query
,
{
pretty
:
true
})
await
request
(
graphqlQuery
)
// check db has manuscript
const
rows
=
await
select
({
...
...
@@ -203,8 +212,6 @@ describe('Submission', () => {
},
}
const
id
=
await
save
(
manuscript
)
// TODO better way to do this
const
newFormData
=
{
data
:
{
id
,
...
...
@@ -226,68 +233,21 @@ describe('Submission', () => {
},
},
}
const
query
=
`
mutation {
updateSubmission(data: {
id: "
${
id
}
",
title: "
${
newFormData
.
data
.
title
}
",
submissionMeta: {
coverLetter: "
${
newFormData
.
data
.
submissionMeta
.
coverLetter
}
",
author: {
firstName: "
${
newFormData
.
data
.
submissionMeta
.
author
.
firstName
}
",
lastName: "
${
newFormData
.
data
.
submissionMeta
.
author
.
lastName
}
",
email: "
${
newFormData
.
data
.
submissionMeta
.
author
.
email
}
",
institution: "
${
newFormData
.
data
.
submissionMeta
.
author
.
institution
}
"
},
correspondent: {
firstName: "
${
newFormData
.
data
.
submissionMeta
.
correspondent
.
firstName
}
",
lastName: "
${
newFormData
.
data
.
submissionMeta
.
correspondent
.
lastName
}
",
email: "
${
newFormData
.
data
.
submissionMeta
.
correspondent
.
email
}
",
institution: "
${
newFormData
.
data
.
submissionMeta
.
correspondent
.
institution
}
"
}
}
}) {
id
}
}
`
/* const query = ` */
/* mutation { */
/* updateSubmission(data: ${JSON.stringify(newFormData.data)}) { */
/* id */
/* } */
/* } */
/* `; */
/* const query = ` */
/* mutation { */
/* updateSubmission(data: ${newFormData.data}) { */
/* id */
/* } */
/* } */
/* `; */
await
request
(
query
)
const
query
=
{
mutation
:
{
updateSubmission
:
{
id
:
true
,
__args
:
{
data
:
{
id
,
...
newFormData
.
data
,
},
},
},
},
}
const
graphqlQuery
=
jsonToGraphQLQuery
(
query
,
{
pretty
:
true
})
await
request
(
graphqlQuery
)
// check new values in db
const
rows
=
await
selectId
(
id
)
...
...
This diff is collapsed.
Click to expand it.
server/submission/package.json
+
1
−
0
View file @
b0bc1dd0
...
...
@@ -12,6 +12,7 @@
"apollo-boost"
:
"^0.1.4"
,
"config"
:
"^1.30.0"
,
"graphql-tag"
:
"^2.8.0"
,
"json-to-graphql-query"
:
"^1.3.0"
,
"lodash"
:
"^4.17.5"
,
"uuid"
:
"^3.2.1"
},
...
...
This diff is collapsed.
Click to expand it.
yarn.lock
+
5
−
1
View file @
b0bc1dd0
...
...
@@ -5955,6 +5955,10 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
json-to-graphql-query@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/json-to-graphql-query/-/json-to-graphql-query-1.3.0.tgz#db52aac03141c2a156bc2e0a6bed2a0149c793c7"
json3@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"
...
...
@@ -10094,7 +10098,7 @@ style-search@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/style-search/-/style-search-0.1.0.tgz#7958c793e47e32e07d2b5cafe5c0bf8e12e77902"
styled-components@3.2.5,
"styled-components@>=2.0 || >=3.0", styled-components@^3.2.5:
"styled-components@>=2.0 || >=3.0", styled-components@^3.2.5:
version "3.2.5"
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-3.2.5.tgz#b5d5d7d618ab240ff10602b5ca5886b8db3d0a0d"
dependencies:
...
...
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