Skip to content
Snippets Groups Projects
Commit 578a2631 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

refactor(*): remove most pubsweet dependencies

parent d6a26e21
No related branches found
No related tags found
1 merge request!87Libs cleanup
Showing
with 273 additions and 73 deletions
......@@ -64,8 +64,6 @@ temp/
# Container data
data/
minio/
# Pubsweet
uploads/
# IDE
......
......@@ -64,8 +64,6 @@ temp/
# Container data
data/
minio/
# Pubsweet
uploads/
# IDE
......
FROM node:20
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y ranger vim
RUN apt-get update && \
apt-get install -y ranger vim
WORKDIR /home/node/app
......
module.exports = [
'./src/models/__tests__/helpers/fake',
'./src/models/activityLog',
'./src/models/chatMessage',
'./src/models/chatThread',
'./src/models/file',
'./src/models/identity',
'./src/models/serviceCredential',
'./src/models/team',
'./src/models/teamMember',
'./src/models/user',
'./src/models/identity',
'./src/models/activityLog',
]
......@@ -3,7 +3,8 @@ set -x
export NODE_CONFIG_DIR='./dev/config'
# This is run through docker. Its CWD will be the root folder.
node_modules/.bin/pubsweet migrate
chmod +x src/cli/coko-server.js
src/cli/coko-server.js migrate
node ./dev/scripts/seedGlobalTeams.js
node ./dev/scripts/ensureTempFolderExists.js
node ./dev/scripts/seedAdmin.js
......
module.exports = {
collectCoverage: false,
// collectCoverageFrom: [
// '<rootDir>/src/models/**/*.model.js',
// '<rootDir>/src/models/**/*.controller.js',
// '<rootDir>/src/models/useTransaction.js',
// '!<rootDir>/src/models/__tests__/helpers/**',
// ],
// coverageDirectory: '<rootDir>/coverage',
projects: [
{
displayName: 'models',
testEnvironment: 'node',
testRegex: 'src/models/__tests__/.+model.test.js$',
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
{
displayName: 'controllers',
testEnvironment: 'node',
testRegex: 'src/models/__tests__/.+controller.test.js$',
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
{
displayName: 'api',
testEnvironment: 'node',
testRegex: 'src/models/__tests__/.+api.test.js$',
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
{
displayName: 'services',
testEnvironment: 'node',
testRegex: 'src/services/__tests__/.+service.test.js$',
// globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
{
displayName: 'utils',
testEnvironment: 'node',
testRegex: 'src/utils/__tests__/.+test.js$',
// globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
{
displayName: 'app',
testEnvironment: 'node',
testRegex: 'src/__tests__/.*\\.test\\.js$',
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
// globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
},
],
maxWorkers: 1,
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
testEnvironment: 'node',
testRegex: '(/src/.*\\.test\\.js$|/__tests__/.*\\.test\\.js$)',
}
......@@ -12,6 +12,10 @@
"license": "MIT",
"author": "Yannis Barlas",
"main": "src/index.js",
"bin": {
"coko-server": "./cli/coko-server.js",
"cs": "./cli/coko-server.js"
},
"scripts": {
"cz": "git-cz",
"prepare": "husky install",
......@@ -32,11 +36,7 @@
"pg": "^8.7.3"
},
"dependencies": {
"@pubsweet/base-model": "^4.0.10",
"@pubsweet/component-send-email": "^0.4.13",
"@pubsweet/db-manager": "^3.1.21",
"@pubsweet/errors": "^2.0.46",
"@pubsweet/logger": "^0.2.56",
"@hapi/joi": "^14.3.0",
"@pubsweet/models": "^0.3.21",
"apollo-server-express": "^2.11.0",
"aws-sdk": "^2.1046.0",
......@@ -45,6 +45,7 @@
"bcrypt": "5.1.1",
"body-parser": "^1.19.0",
"command-exists": "^1.2.9",
"commander": "^2.20.0",
"config": "^3.3.2",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
......@@ -62,12 +63,14 @@
"http-status-codes": "^1.4.0",
"image-size": "^1.0.2",
"jsonwebtoken": "^8.4.0",
"knex": "^0.21.1",
"lodash": "^4.17.20",
"mime-types": "^2.1.34",
"moment": "^2.29.1",
"morgan": "^1.10.0",
"multer": "^1.1.0",
"node-cron": "^2.0.3",
"nodemailer": "^6.4.18",
"objection": "^2.2.15",
"passport": "^0.4.1",
"passport-anonymous": "^1.0.1",
......@@ -75,9 +78,10 @@
"passport-local": "^1.0.0",
"pg": "^8.7.3",
"pg-boss": "^5.2.0",
"pubsweet": "^5.1.25",
"sharp": "^0.29.3",
"subscriptions-transport-ws": "^0.9.19",
"tmp-promise": "^2.0.0",
"umzug": "^2.1.0",
"uuid": "^8.3.2",
"waait": "^1.0.5"
},
......@@ -85,10 +89,12 @@
"@coko/lint": "^2.0.0",
"faker": "^5.5.3",
"jest": "^26.6.3",
"jest-environment-node": "^26.6.2",
"node-wait-for-it": "^0.2.0",
"nodemon": "^3.0.1",
"standard-version": "^7.1.0",
"supertest": "^3.1.0"
"supertest": "^3.1.0",
"winston": "^2.3.1"
},
"publishConfig": {
"access": "public"
......
const fs = require('fs')
const path = require('path')
const { migrate } = require('@pubsweet/db-manager')
const migrate = require('../dbManager/migrate')
const { User } = require('../models')
const api = require('./helpers/api')
......
const api = require('../app')(require('express')())
const db = require('../dbManager/db')
const clearDb = require('../models/__tests__/_clearDb')
const { User } = require('../models')
......@@ -16,6 +17,10 @@ describe('api/app locals', () => {
return User.insert(userData)
})
afterAll(() => {
db.destroy()
})
it('exposes models', async () => {
const userInstance = new api.locals.models.User()
expect(userInstance.type).toEqual('user')
......
......@@ -7,6 +7,7 @@ const clearDb = require('../../models/__tests__/_clearDb')
const api = require('../helpers/api')
const authentication = require('../../authentication')
const { User } = require('../../models')
const db = require('../../dbManager/db')
describe('GraphQL authentication', () => {
let token
......@@ -23,6 +24,10 @@ describe('GraphQL authentication', () => {
token = authentication.token.create(user)
})
afterAll(() => {
db.destroy()
})
describe('loginUser mutation', () => {
it('can log in', async () => {
const { body } = await api.graphql.query(
......
const { User } = require('@pubsweet/models')
const errors = require('@pubsweet/errors')
const errors = require('../../errors')
const api = require('../helpers/api')
const authentication = require('../../authentication')
const clearDb = require('../../models/__tests__/_clearDb')
const db = require('../../dbManager/db')
/* eslint-disable-next-line jest/no-disabled-tests */
describe.skip('GraphQL errors', () => {
......@@ -20,6 +21,10 @@ describe.skip('GraphQL errors', () => {
token = authentication.token.create(user)
})
afterAll(() => {
db.destroy()
})
it('should pass GraphQLError to clients', async () => {
const { body } = await api.graphql.query(
`mutation($input: UserInput) {
......
......@@ -4,6 +4,7 @@ const api = require('../helpers/api')
const authentication = require('../../authentication')
const { User } = require('../../models')
const clearDb = require('../../models/__tests__/_clearDb')
const db = require('../../dbManager/db')
describe('GraphQL core mutations', () => {
let token
......@@ -20,6 +21,10 @@ describe('GraphQL core mutations', () => {
token = authentication.token.create(user)
})
afterAll(() => {
db.destroy()
})
describe('mutations', () => {
// it.skip('can create a user', async () => {
// const { body } = await api.graphql.query(
......
......@@ -2,6 +2,7 @@ const { Team, TeamMember, User } = require('../../models')
const clearDb = require('../../models/__tests__/_clearDb')
const api = require('../helpers/api')
const authentication = require('../../authentication')
const db = require('../../dbManager/db')
describe('GraphQL core queries', () => {
let token
......@@ -18,6 +19,10 @@ describe('GraphQL core queries', () => {
token = authentication.token.create(user)
})
afterAll(() => {
db.destroy()
})
it('can resolve all users', async () => {
const { body } = await api.graphql.query(
`{ users { result { username } } }`,
......
/* eslint-disable jest/no-commented-out-tests */
// const { User } = require('@pubsweet/models')
// const { fixtures } = require('@pubsweet/model-user/test')
// const WebSocket = require('ws')
// const {
// ApolloClient,
// createHttpLink,
// gql,
// InMemoryCache,
// split,
// } = require('@apollo/client')
// const { WebSocketLink } = require('@apollo/client/link/ws')
// const { getMainDefinition } = require('@apollo/client/utilities')
// const FormData = require('form-data')
// const fetch = require('node-fetch')
// const wait = require('waait')
// const { startServer } = require('../../src')
// const authentication = require('../../src/authentication')
// const cleanDB = require('../helpers/db_cleaner')
// function generateFetchOptions(token, fileSize) {
// // This dance needs to happen because apollo-upload-client is 'untestable':
// // https://github.com/jaydenseric/apollo-upload-client/issues/32#issuecomment-327694315
// let variables
// let size
// let query
// if (fileSize) {
// variables = {
// file: null,
// fileSize,
// }
// query =
// 'mutation uploadFile($file: Upload!, $fileSize: Int) { upload(file: $file, fileSize: $fileSize) { url, __typename }}'
// size = fileSize
// } else {
// variables = {
// file: null,
// }
// query =
// 'mutation uploadFile($file: Upload!) { upload(file: $file) { url, __typename }}'
// size = 1000000
// }
// const body = new FormData()
// body.append(
// 'operations',
// JSON.stringify({
// operationName: 'uploadFile',
// variables,
// query,
// }),
// )
// body.append('map', JSON.stringify({ 1: ['variables.file'] }))
// body.append('1', 'a'.repeat(size), { filename: 'a.txt' })
// const options = {
// method: 'POST',
// body,
// headers: {
// Authorization: `Bearer ${token}`,
// },
// }
// return options
// }
// describe('GraphQL subscriptions', () => {
// let token
// let user
// let server
// let apolloClient
// let wsLink
// beforeAll(async () => {
// server = await startServer()
// })
// beforeEach(async () => {
// await cleanDB()
// user = await new User(fixtures.user).save()
// token = authentication.token.create(user)
// wsLink = new WebSocketLink({
// uri: `ws://localhost:4000/subscriptions`,
// options: {
// connectionParams: {
// authToken: token,
// },
// },
// reconnect: false,
// webSocketImpl: WebSocket,
// })
// const httpLink = createHttpLink({ fetch })
// const link = split(
// ({ query }) => {
// const { kind, operation } = getMainDefinition(query)
// return kind === 'OperationDefinition' && operation === 'subscription'
// },
// wsLink,
// httpLink,
// )
// const config = {
// link,
// cache: new InMemoryCache(),
// }
// apolloClient = new ApolloClient(config)
// })
// afterEach(async () => {
// await wsLink.subscriptionClient.client.close()
// })
// afterAll(done => server.close(done))
// it('reports progress when fileSize is given', async () => {
// let done
// let progress = 0
// const subscriptionPromise = new Promise((resolve, reject) => {
// apolloClient
// .subscribe({
// query: gql`
// subscription onUploadProgress {
// uploadProgress
// }
// `,
// })
// .subscribe({
// next: async res => {
// expect(res.data.uploadProgress).toBeGreaterThanOrEqual(progress)
// progress = res.data.uploadProgress
// expect(progress).toBeGreaterThan(-1)
// expect(progress).toBeLessThanOrEqual(100)
// // sometimes the last notification is sent slightly before
// // fetch completes, resulting in an unresolved promise, so
// // we just wait a tiny bit.
// await wait(100)
// if (done) resolve('done')
// },
// error: reject,
// })
// })
// await fetch(
// `http://localhost:4000/graphql`,
// generateFetchOptions(token, 1000000),
// )
// done = true
// expect(await subscriptionPromise).toBe('done')
// })
// it('reports progress when fileSize is not given', async () => {
// let done
// let progress = 0
// const subscriptionPromise = new Promise((resolve, reject) => {
// apolloClient
// .subscribe({
// query: gql`
// subscription onUploadProgress {
// uploadProgress
// }
// `,
// })
// .subscribe({
// next: async res => {
// expect(res.data.uploadProgress).toBeGreaterThanOrEqual(progress)
// progress = res.data.uploadProgress
// expect(progress).toBeGreaterThan(-1)
// expect(progress).toBeLessThanOrEqual(1000000)
// // sometimes the last notification is sent slightly before
// // fetch completes, resulting in an unresolved promise, so
// // we just wait a tiny bit.
// await wait(100)
// if (done) resolve('done')
// },
// error: reject,
// })
// })
// await fetch(`http://localhost:4000/graphql`, generateFetchOptions(token))
// done = true
// expect(await subscriptionPromise).toBe('done')
// })
// })
......@@ -2,6 +2,7 @@ const api = require('../helpers/api')
const authentication = require('../../authentication')
const clearDb = require('../../models/__tests__/_clearDb')
const { User } = require('../../models')
const db = require('../../dbManager/db')
describe('GraphQL uploads', () => {
let token
......@@ -18,6 +19,10 @@ describe('GraphQL uploads', () => {
token = authentication.token.create(user)
})
afterAll(() => {
db.destroy()
})
it('can upload a file', async () => {
const { body } = await api.request
.post('/graphql')
......
/* eslint-disable no-param-reassign */
const configureApp = app => {
// console.log('og', app)
app.get('/verify', (req, res) => res.send('hi'))
// Actions to perform when the HTTP server starts listening
......
......@@ -2,6 +2,7 @@
const { boss, subscribeJobsToQueue } = require('../jobs')
const { jobs } = require('../services')
const db = require('../dbManager/db')
// const { renewAuthTokens } = require('../utils/tokens')
const freezeTime = 1701856542000
......@@ -86,6 +87,10 @@ describe.skip('jobs service', () => {
await subscribeJobsToQueue()
})
afterAll(() => {
db.destroy()
})
it('registers jobs', async () => {
expect(Object.keys(boss.subscriptions)).toEqual([
jobs.REFRESH_TOKEN_EXPIRED,
......
/* eslint-disable jest/no-disabled-tests, jest/no-done-callback */
const { startJobQueue } = require('../../jobs')
const db = require('../../dbManager/db')
const someHandler = async job => {
expect(job.data.param).toEqual('aThing')
......@@ -14,6 +15,10 @@ describe.skip('jobs', () => {
jobQueue = await startJobQueue()
})
afterAll(() => {
db.destroy()
})
it('submits a job, runs it, and notifies on completion', async done => {
const queueName = 'aJobQueue'
......
......@@ -3,6 +3,7 @@
const path = require('path')
const { spawn } = require('child_process')
const { startJobQueue } = require('../../jobs')
const db = require('../../dbManager/db')
describe('job runner in a different process', () => {
let jobQueue
......@@ -11,6 +12,10 @@ describe('job runner in a different process', () => {
jobQueue = await startJobQueue()
})
afterAll(() => {
db.destroy()
})
it('submits a job and gets notified on completion', async done => {
const queueName = 'aJobQueue2'
......
/* eslint-disable jest/no-disabled-tests, jest/no-done-callback */
const startServer = require('../../startServer')
const db = require('../../dbManager/db')
const { connectToJobQueue } = require('../../jobs')
const someHandler = async job => {
......@@ -16,6 +16,10 @@ describe.skip('integrated job queue', () => {
server = await startServer()
})
afterAll(() => {
db.destroy()
})
// This is to verify that pg-boss has been setup with pg-boss.start()
// in the process of starting pubsweet-server
it('ready to connect and process jobs when server starts', async done => {
......
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