diff --git a/packages/xpub-faraday-server/src/AuthorBackend.js b/packages/xpub-faraday-server/src/AuthorBackend.js index 082a4877df54a6fc25e6e39d93cfc0776c4d94ec..5e18d45c1dc1baae93c5b63fdc475745dfb1e623 100644 --- a/packages/xpub-faraday-server/src/AuthorBackend.js +++ b/packages/xpub-faraday-server/src/AuthorBackend.js @@ -9,7 +9,6 @@ const AuthorBackend = app => { authBearer, bodyParser.json(), async (req, res, next) => { - // console.log(app.locals) try { if (!req.params.fragmentId) { res.status(400).json({ error: 'Fragment ID is required' }) @@ -31,9 +30,9 @@ const AuthorBackend = app => { const nameAuthors = fragment.authors.filter( author => - author.first_name === req.body.first_name && - author.middle_name === req.body.middle_name && - author.last_name === req.body.last_name, + author.firstName === req.body.firstName && + author.middleName === req.body.middleName && + author.lastName === req.body.lastName, ) if (nameAuthors.length > 0) { @@ -45,6 +44,7 @@ const AuthorBackend = app => { fragment = await fragment.save() res.status(200).json(fragment) } catch (e) { + console.log(e) if (e.name === 'NotFoundError') { res.status(e.status).json({ error: 'Fragment not found' }) return diff --git a/packages/xpub-faraday-server/src/AuthorBackend.test.js b/packages/xpub-faraday-server/src/AuthorBackend.test.js index 87e5980d79c3e192e482894eb9847a97ab73539b..d05c25f4f3691d8361497c9527f9655c7b1a870e 100644 --- a/packages/xpub-faraday-server/src/AuthorBackend.test.js +++ b/packages/xpub-faraday-server/src/AuthorBackend.test.js @@ -2,17 +2,32 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' process.env.SUPPRESS_NO_CONFIG_WARNING = true const bodyParser = require('body-parser') -// const express = require('express') +const express = require('express') const supertest = require('supertest') const component = require('..') -const app = require('../../xpub-faraday/app') const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNlYmkiLCJpZCI6IjVlMTRiY2IyLWQ5ZTEtNDZjOS05ZDI0LTM3YTk4MDhmMjFmYiIsImlhdCI6MTUxNjExODAxMSwiZXhwIjoxNTE2MjA0NDExfQ.tqH0Nnpiec2c1FPL2K5fK4krHGN2SrYyMbqVSnYSpog' +const author = { + first_name: 'marcel', + middle_name: 'sss', + last_name: 'iures', + email: 'email@ciment2.com', + affiliation: 'UTI', + country: '', + is_corresponding: true, + is_submitting: true, + save: jest.fn(), +} function makeApp(response) { - // const app = express() + const app = express() app.use(bodyParser.json()) + app.locals = { + passport: { + authenticate: jest.fn(() => () => Promise.resolve(true)), + }, + } app.locals.models = { Fragment: { find: jest.fn( @@ -23,16 +38,16 @@ function makeApp(response) { ), }, } - component.backend(app) + component.backend()(app) return supertest(app) } describe('Author Backend API', () => { it('should return error if fragment is not found', () => - makeApp() - .post('/api/fragments/cf7b9ea6-47ac-4188-b0ef-f89cc17364fe2/authors') + makeApp(new Error('Not Found')) + .post('/api/fragments/cf7b9ea6-47ac-4188-b0ef-f89cc17364fe/authors') .set('Content-Type', 'application/json') - .set('Authentication', `Bearer ${token}`) - .send({}) + // .set('Authentication', `Bearer ${token}`) + .send(author) .expect(404, '"error": "Fragment not found"')) }) diff --git a/packages/xpub-faraday/config/validations.js b/packages/xpub-faraday/config/validations.js index 46db4f99f1ff03fd5d8c004ca6630f32f12e45af..f9d3945aafba228c1ca996a5370ba4119198754f 100644 --- a/packages/xpub-faraday/config/validations.js +++ b/packages/xpub-faraday/config/validations.js @@ -53,16 +53,16 @@ module.exports = { decision: Joi.object(), authors: Joi.array().items( Joi.object({ - first_name: Joi.string().required(), - last_name: Joi.string().required(), - middle_name: Joi.string().allow(''), + firstName: Joi.string().required(), + lastName: Joi.string().required(), + middleName: Joi.string().allow(''), email: Joi.string() .email() .required(), affiliation: Joi.string().required(), country: Joi.string().allow(''), - is_submitting: Joi.boolean(), - is_corresponding: Joi.boolean(), + isSubmitting: Joi.boolean(), + isCorresponding: Joi.boolean(), }), ), },