Commit c8cbf320 authored by Jennifer Spencer's avatar Jennifer Spencer
Browse files

WIP refactor: request user details from orchid within createSubmission...

WIP refactor: request user details from orchid within createSubmission mutation & test for orchid error
parent 983f4e53
const lodash = require('lodash')
const logger = require('@pubsweet/logger')
const User = require('pubsweet-server/src/models/User')
const db = require('../db-helpers/')
const fetchOrcidDetails = require('../auth/fetchUserDetails')
/**
* types & input types should be kept in sync
......@@ -175,10 +178,14 @@ const resolvers = {
},
Mutation: {
async createSubmission(_, { data }, ctx) {
const orcidData = {
submissionMeta: {
author: await db.getOrcidData(ctx.user),
},
const orcidData = {}
try {
const userData = await User.find(ctx.user)
orcidData.submissionMeta = {
author: await fetchOrcidDetails(userData),
}
} catch (err) {
logger.error(err)
}
const manuscript = lodash.merge(emptyManuscript, orcidData)
const manuscriptDb = db.manuscriptGqlToDb(manuscript, ctx.user)
......
......@@ -14,9 +14,12 @@ const {
const { jsonToGraphQLQuery } = require('json-to-graphql-query')
const Joi = require('joi')
const replaySetup = require('../../test/helpers/replay-setup')
const userData = {
username: 'testuser',
orcid: 'testuser-orcid-id',
orcid: '0000-0003-3146-0256',
oauth: { accessToken: 'f7617529-f46a-40b1-99f4-4181859783ca' },
}
const getClient = async () => {
......@@ -40,6 +43,7 @@ describe('Submission', () => {
let request
beforeEach(async () => {
replaySetup('')
await createTables(true)
request = await getClient()
})
......@@ -280,6 +284,35 @@ describe('Submission', () => {
expect(error).toBeNull()
})
it('createSubmission - an error in the orcid request leaves fields unpopulated', async () => {
replaySetup('error')
const query = {
mutation: {
createSubmission: {
submissionMeta: {
author: {
firstName: true,
lastName: true,
email: true,
institution: true,
},
},
},
},
}
const { body } = await request(query)
expect(body.data.createSubmission).toEqual({
submissionMeta: {
author: {
firstName: '',
lastName: '',
email: '',
institution: '',
},
},
})
})
it('updateSubmission updates the current submission for user with data', async () => {
const manuscript = {
title: 'title',
......
......@@ -7,4 +7,6 @@ const Replay = require('replay')
// When writing or updating tests you'll want to change the mode
// see https://github.com/assaf/node-replay#settings
Replay.fixtures = path.join(__dirname, '..', 'http-mocks')
module.exports = subFolder => {
Replay.fixtures = path.join(__dirname, '..', 'http-mocks', subFolder)
}
......@@ -5,7 +5,7 @@ authorization: Bearer f7617529-f46a-40b1-99f4-4181859783ca
HTTP/1.1 200 OK
server: nginx/1.10.0
date: Tue, 01 May 2018 11:57:06 GMT
date: Wed, 09 May 2018 16:26:55 GMT
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
connection: close
......
GET /v2.1/0000-0003-3146-0256/person
accept-encoding: gzip, deflate
accept: application/json
authorization: Bearer f7617529-f46a-40b1-99f4-4181859783ca
HTTP/1.1 200 OK
server: nginx/1.10.0
date: Wed, 09 May 2018 16:26:55 GMT
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
connection: close
access-control-allow-origin: *
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: 0
x-xss-protection: 1; mode=block
x-frame-options: DENY
x-content-type-options: nosniff
{"last-modified-date":{"value":1525104549715},"name":{"created-date":{"value":1523279444398},"last-modified-date":{"value":1523279444675},"given-names":{"value":"Test"},"family-name":{"value":"User"},"credit-name":null,"source":null,"visibility":"PUBLIC","path":"0000-0003-3146-0256"},"other-names":{"last-modified-date":null,"other-name":[],"path":"/0000-0003-3146-0256/other-names"},"biography":null,"researcher-urls":{"last-modified-date":null,"researcher-url":[],"path":"/0000-0003-3146-0256/researcher-urls"},"emails":{"last-modified-date":{"value":1525104549715},"email":[{"created-date":{"value":1523279444675},"last-modified-date":{"value":1525104549715},"source":{"source-orcid":{"uri":"https://sandbox.orcid.org/0000-0003-3146-0256","path":"0000-0003-3146-0256","host":"sandbox.orcid.org"},"source-client-id":null,"source-name":{"value":"Test User"}},"email":"elife@mailinator.com","path":null,"visibility":"PUBLIC","verified":true,"primary":true,"put-code":null}],"path":"/0000-0003-3146-0256/email"},"addresses":{"last-modified-date":null,"address":[],"path":"/0000-0003-3146-0256/address"},"keywords":{"last-modified-date":null,"keyword":[],"path":"/0000-0003-3146-0256/keywords"},"external-identifiers":{"last-modified-date":null,"external-identifier":[],"path":"/0000-0003-3146-0256/external-identifiers"},"path":"/0000-0003-3146-0256/person"}
\ No newline at end of file
GET /v2.1/0000-0003-3146-0256/email
GET /v2.1/0000-0003-3146-0256/employments
accept-encoding: gzip, deflate
accept: application/json
authorization: Bearer f7617529-f46a-40b1-99f4-4181859783ca
HTTP/1.1 200 OK
HTTP/1.1 500 OK
server: nginx/1.10.0
date: Tue, 01 May 2018 11:57:06 GMT
date: Wed, 09 May 2018 16:26:56 GMT
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
connection: close
......@@ -17,4 +17,4 @@ x-xss-protection: 1; mode=block
x-frame-options: DENY
x-content-type-options: nosniff
{"last-modified-date":{"value":1525104549715},"email":[{"created-date":{"value":1523279444675},"last-modified-date":{"value":1525104549715},"source":{"source-orcid":{"uri":"https://sandbox.orcid.org/0000-0003-3146-0256","path":"0000-0003-3146-0256","host":"sandbox.orcid.org"},"source-client-id":null,"source-name":{"value":"Test User"}},"email":"elife@mailinator.com","path":null,"visibility":"PUBLIC","verified":true,"primary":true,"put-code":null}],"path":"/0000-0003-3146-0256/email"}
\ No newline at end of file
{"error":"orcid-error"}
\ No newline at end of file
GET /v2.1/0000-0003-3146-0256/person
accept-encoding: gzip, deflate
accept: application/json
authorization: Bearer f7617529-f46a-40b1-99f4-4181859783ca
HTTP/1.1 200 OK
server: nginx/1.10.0
date: Wed, 09 May 2018 16:26:56 GMT
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
connection: close
access-control-allow-origin: *
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: 0
x-xss-protection: 1; mode=block
x-frame-options: DENY
x-content-type-options: nosniff
{"last-modified-date":{"value":1525104549715},"name":{"created-date":{"value":1523279444398},"last-modified-date":{"value":1523279444675},"given-names":{"value":"Test"},"family-name":{"value":"User"},"credit-name":null,"source":null,"visibility":"PUBLIC","path":"0000-0003-3146-0256"},"other-names":{"last-modified-date":null,"other-name":[],"path":"/0000-0003-3146-0256/other-names"},"biography":null,"researcher-urls":{"last-modified-date":null,"researcher-url":[],"path":"/0000-0003-3146-0256/researcher-urls"},"emails":{"last-modified-date":{"value":1525104549715},"email":[{"created-date":{"value":1523279444675},"last-modified-date":{"value":1525104549715},"source":{"source-orcid":{"uri":"https://sandbox.orcid.org/0000-0003-3146-0256","path":"0000-0003-3146-0256","host":"sandbox.orcid.org"},"source-client-id":null,"source-name":{"value":"Test User"}},"email":"elife@mailinator.com","path":null,"visibility":"PUBLIC","verified":true,"primary":true,"put-code":null}],"path":"/0000-0003-3146-0256/email"},"addresses":{"last-modified-date":null,"address":[],"path":"/0000-0003-3146-0256/address"},"keywords":{"last-modified-date":null,"keyword":[],"path":"/0000-0003-3146-0256/keywords"},"external-identifiers":{"last-modified-date":null,"external-identifier":[],"path":"/0000-0003-3146-0256/external-identifiers"},"path":"/0000-0003-3146-0256/person"}
\ No newline at end of file
Markdown is supported
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