Skip to content
Snippets Groups Projects
Commit b0bc1dd0 authored by Mihail Dunaev's avatar Mihail Dunaev
Browse files

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!29Get current ms
......@@ -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(query)
const { body } = await request(graphqlQuery)
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)
......
......@@ -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"
},
......
......@@ -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:
......
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