Skip to content
Snippets Groups Projects
Commit f6ddb572 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

Merge branch 'faraday-master' of gitlab.coko.foundation:xpub/xpub into faraday-master

parents 54d7475a e94a9eb8
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
"files": [ "files": [
"src" "src"
], ],
"scripts": {
"test": "jest"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://gitlab.coko.foundation/xpub/xpub" "url": "https://gitlab.coko.foundation/xpub/xpub"
...@@ -18,8 +21,12 @@ ...@@ -18,8 +21,12 @@
}, },
"peerDependencies": { "peerDependencies": {
"@pubsweet/logger": "^0.0.1", "@pubsweet/logger": "^0.0.1",
"pubsweet-server": "^1.0.1",
"pubsweet": "^1.1.1", "pubsweet": "^1.1.1",
"pubsweet-client": "^1.1.1" "pubsweet-client": "^1.1.1",
"pubsweet-server": "^1.0.1"
},
"devDependencies": {
"jest": "^22.1.1",
"supertest": "^3.0.0"
} }
} }
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const AuthorBackend = app => { const AuthorBackend = app => {
const authBearer = app.locals.passport.authenticate('bearer', {
session: false,
})
app.post( app.post(
'/api/fragments/:fragmentId/authors', '/api/fragments/:fragmentId/authors',
authBearer,
bodyParser.json(), bodyParser.json(),
async (req, res, next) => { async (req, res, next) => {
// console.log(app.locals)
try { try {
if (!req.params.fragmentId) { if (!req.params.fragmentId) {
res.status(400).json({ error: 'Fragment ID is required' }) res.status(400).json({ error: 'Fragment ID is required' })
...@@ -55,6 +60,7 @@ const AuthorBackend = app => { ...@@ -55,6 +60,7 @@ const AuthorBackend = app => {
) )
app.delete( app.delete(
'/api/fragments/:fragmentId/authors/:authorEmail', '/api/fragments/:fragmentId/authors/:authorEmail',
authBearer,
async (req, res, next) => { async (req, res, next) => {
const { fragmentId, authorEmail } = req.params const { fragmentId, authorEmail } = req.params
try { try {
...@@ -63,7 +69,7 @@ const AuthorBackend = app => { ...@@ -63,7 +69,7 @@ const AuthorBackend = app => {
res.status(404).json({ error: 'Fragment does not have any authors' }) res.status(404).json({ error: 'Fragment does not have any authors' })
return return
} }
// find author in authors list by email
if (fragment.authors.length === 0) { if (fragment.authors.length === 0) {
res.status(404).json({ error: 'Fragment does not have any authors' }) res.status(404).json({ error: 'Fragment does not have any authors' })
return return
......
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true
const bodyParser = require('body-parser')
// const express = require('express')
const supertest = require('supertest')
const component = require('..')
const app = require('../../xpub-faraday/app')
const token =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNlYmkiLCJpZCI6IjVlMTRiY2IyLWQ5ZTEtNDZjOS05ZDI0LTM3YTk4MDhmMjFmYiIsImlhdCI6MTUxNjExODAxMSwiZXhwIjoxNTE2MjA0NDExfQ.tqH0Nnpiec2c1FPL2K5fK4krHGN2SrYyMbqVSnYSpog'
function makeApp(response) {
// const app = express()
app.use(bodyParser.json())
app.locals.models = {
Fragment: {
find: jest.fn(
() =>
response instanceof Error
? Promise.reject(response)
: Promise.resolve(response),
),
},
}
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')
.set('Content-Type', 'application/json')
.set('Authentication', `Bearer ${token}`)
.send({})
.expect(404, '"error": "Fragment not found"'))
})
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"pubsweet-component-xpub-manuscript": "^0.0.2", "pubsweet-component-xpub-manuscript": "^0.0.2",
"pubsweet-component-xpub-review": "^0.0.2", "pubsweet-component-xpub-review": "^0.0.2",
"pubsweet-component-xpub-submit": "^0.0.2", "pubsweet-component-xpub-submit": "^0.0.2",
"pubsweet-server": "^1.0.1", "pubsweet-server": "1.0.5",
"react": "^15.6.1", "react": "^15.6.1",
"react-dnd": "^2.5.4", "react-dnd": "^2.5.4",
"react-dnd-html5-backend": "^2.5.4", "react-dnd-html5-backend": "^2.5.4",
...@@ -39,10 +39,10 @@ ...@@ -39,10 +39,10 @@
"redux-form": "^7.0.3", "redux-form": "^7.0.3",
"redux-logger": "^3.0.1", "redux-logger": "^3.0.1",
"winston": "^2.4.0", "winston": "^2.4.0",
"xpub-faraday-server": "^0.0.1",
"xpub-journal": "^0.0.2", "xpub-journal": "^0.0.2",
"xpub-selectors": "^0.0.2", "xpub-selectors": "^0.0.2",
"xpub-theme": "^0.0.2", "xpub-theme": "^0.0.2"
"xpub-faraday-server": "^0.0.1"
}, },
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
......
This diff is collapsed.
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