Commit 8868af9c authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

fix(test): make test work for editoria

parent 88bb4caf
module.exports = {
collectCoverage: false,
collectCoverageFrom: [
'**/*.{js,jsx}',
'!**/*test.{js,jsx}',
'!**/test/**',
'!**/node_modules/**',
'!**/config/**',
'!**/coverage/**',
],
coverageDirectory: '<rootDir>/coverage',
projects: [
'<rootDir>/packages/data-model/jest.config.js',
'<rootDir>/packages/api/jest.config.js',
],
}
......@@ -2,10 +2,11 @@
"author": "Yannis Barlas, Alexandros Georgantas",
"description": "Monorepo grouping all the different parts of the Editoria project",
"devDependencies": {
"babel-eslint": "^8.0.3",
"babel-preset-es2015": "^6.24.1",
"@commitlint/cli": "^6.0.5",
"@commitlint/config-conventional": "^6.0.4",
"babel-eslint": "^8.0.3",
"babel-jest": "^24.8.0",
"babel-preset-es2015": "^6.24.1",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.13.1",
......@@ -18,16 +19,17 @@
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-standard": "^3.0.1",
"jest": "^24.8.0",
"lerna": "^2.5.1",
"lint-staged": "^6.0.0",
"prettier": "^1.8.2",
"standard-version": "^4.4.0",
"style-loader": "^0.21.0",
"stylelint": "^9.2.1",
"stylelint-config-recommended": "^2.1.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-order": "^1.0.0",
"stylelint-processor-styled-components": "^1.3.1",
"standard-version": "^4.4.0"
"stylelint-processor-styled-components": "^1.3.1"
},
"license": "MIT",
"name": "editoria-monorepo",
......@@ -60,7 +62,12 @@
"babel-preset-stage-0": "^6.24.1"
},
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/react-adopt", "**/react-powerplug"]
"packages": [
"packages/*"
],
"nohoist": [
"**/react-adopt",
"**/react-powerplug"
]
}
}
module.exports = {
user: {
type: 'user',
username: 'testuser',
email: 'test@example.com',
password: 'test',
},
addTag: [
{
tagType: 'block',
label: 'tag1',
},
{
tagType: 'inline',
label: 'tag2',
},
],
updateTag: [
{
tagType: 'inline',
label: 'tag1new',
},
],
}
const { CustomTag } = require('editoria-data-model/src').models
const omit = require('lodash/omit')
const pick = require('lodash/pick')
const map = require('lodash/map')
const {
editoriaDataModel: {
models: { User },
},
} = require('editoria-data-model')
const { dbCleaner, api } = require('pubsweet-server/test')
const fixtures = require('./helpers/fixtures')
const authentication = require('pubsweet-server/src/authentication')
describe('Tag mutations', () => {
// let token
// let user
beforeEach(async () => {
await dbCleaner()
})
it('can add a custom tag', async () => {
const user = await new User(fixtures.user).save()
const token = authentication.token.create(user)
const {
body: {
data: { addCustomTag },
},
} = await api.graphql.query(
`mutation($input: [CustomTagAddInput]!) {
addCustomTag(input: $input) {
id
label
tagType
}
}`,
{
input: fixtures.addTag,
},
token,
)
expect(map(addCustomTag, tag => omit(tag, ['id']))).toEqual(fixtures.addTag)
})
it('can update a custom tag', async () => {
const user = await new User(fixtures.user).save()
const token = authentication.token.create(user)
const customTag = await Promise.all(
fixtures.addTag.map(async tag => {
const addTag = await new CustomTag(tag).save()
return addTag
}),
)
fixtures.updateTag[0].id = customTag[0].id
const {
body: {
data: { updateCustomTag },
},
} = await api.graphql.query(
`mutation($input: [CustomTagUpdateInput]!) {
updateCustomTag(input: $input) {
id
label
tagType
}
}`,
{
input: fixtures.updateTag,
},
token,
)
const resultTag = [fixtures.addTag[1], fixtures.updateTag[0]]
const compareCustomTag = map(updateCustomTag, tag =>
pick(tag, ['label', 'tagType']),
)
expect(compareCustomTag).toEqual(map(resultTag, tag => omit(tag, ['id'])))
})
it('can delete a custom tag', async () => {
const user = await new User(fixtures.user).save()
const token = authentication.token.create(user)
const customTag = await Promise.all(
fixtures.addTag.map(async tag => {
const addTag = await new CustomTag(tag).save()
return addTag
}),
)
const deleteTag = {
id: customTag[0].id,
deleted: true,
}
const {
body: {
data: { updateCustomTag },
},
} = await api.graphql.query(
`mutation($input: [CustomTagUpdateInput]!) {
updateCustomTag(input: $input) {
id
label
tagType
}
}`,
{
input: [deleteTag],
},
token,
)
const compareCustomTag = map(customTag, tag =>
pick(tag, ['id', 'label', 'tagType']),
)
expect(updateCustomTag).toEqual([compareCustomTag[1]])
})
})
export DB_PORT='5460'
export DB_NAME='editoria_test'
export DB_USER='test'
export DB_PASSWORD='secretpassword'
const path = require('path')
const winston = require('winston')
module.exports = {
'pubsweet-server': {
db: {
port: 5460,
user: 'test',
password: 'secretpassword',
database: global.__testDbName || 'editoria_test',
},
enableExperimentalGraphql: true,
logger: new winston.Logger({
transports: [
new winston.transports.Console({
colorize: true,
}),
],
}),
pool: { min: 0, max: 10, idleTimeoutMillis: 1000 },
port: 4000,
secret: 'test',
sse: false,
uploads: 'uploads',
},
pubsweet: {
components: [
'@pubsweet/model-user',
'@pubsweet/model-team',
'./customTag',
'editoria-data-model/src/customTag',
],
},
authsome: {
mode: path.resolve(__dirname, 'auth'),
teams: {
teamTest: {
name: 'Contributors',
},
},
},
}
const logger = require('@pubsweet/logger')
const { CustomTag } = require('editoria-data-model/src').models
const getCustomTags = async (_, {}, ctx) => {
const customTags = await CustomTag.all()
const getCustomTags = async (_, input, ctx) => {
const customTags = await CustomTag.query().where({ deleted: false })
if (!customTags) {
throw new Error(`CustomTags error: Could not fetch Tags`)
}
......@@ -12,14 +12,15 @@ const getCustomTags = async (_, {}, ctx) => {
const addCustomTag = async (_, { input }, ctx) => {
try {
Promise.all(
await Promise.all(
input.map(async tag => {
const { label, tagType } = tag
await new CustomTag({ label, tagType }).save()
}),
)
const customTags = await CustomTag.all()
const customTags = await CustomTag.query().where({ deleted: false })
return customTags
} catch (e) {
logger.error(e)
......@@ -29,7 +30,7 @@ const addCustomTag = async (_, { input }, ctx) => {
const updateCustomTag = async (_, { input }, ctx) => {
try {
Promise.all(
await Promise.all(
input.map(async tag => {
const { id, deleted, tagType, label } = tag
await CustomTag.query().patchAndFetchById(id, {
......@@ -41,7 +42,8 @@ const updateCustomTag = async (_, { input }, ctx) => {
)
logger.info(`Custom Tag component with id ${updateCustomTag.id} deleted`)
const customTags = await CustomTag.all()
const customTags = await CustomTag.query().where({ deleted: false })
return customTags
} catch (e) {
logger.error(e)
......
module.exports = {
displayName: 'api',
testEnvironment: 'jest-environment-db',
testRegex: '.*test.js$',
testPathIgnorePatterns: [
'./config',
'./__tests__/helpers',
'./node_modules/',
],
}
......@@ -8,6 +8,9 @@
"pubsweet-component",
"graphql"
],
"scripts": {
"test": "jest"
},
"author": "Alexandros Georgantas",
"license": "ISC",
"dependencies": {
......
......@@ -5,8 +5,7 @@
"main": "index.js",
"scripts": {
"styleguide": "styleguidist server",
"styleguide:build": "styleguidist build",
"test": "echo \"Error: no test specified\" && exit 1"
"styleguide:build": "styleguidist build"
},
"keywords": [
"pubsweet-component",
......
......@@ -3,9 +3,6 @@
"version": "0.1.6",
"description": "Common react components for the editoria project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
......
......@@ -4,7 +4,7 @@
"description": "The application dashboard for the Editoria project.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\""
},
"keywords": [
"pubsweet-component",
......
const path = require('path')
process.env.NODE_CONFIG_DIR = path.resolve(__dirname)
export DB_PORT='5499'
export DB_NAME='test'
export DB_USER='testuser'
export DB_PASSWORD='testpass'
echo $DB_NAME
const auth = () => true
module.exports = auth
export DB_PORT='5460'
export DB_NAME='editoria_test'
export DB_USER='test'
export DB_PASSWORD='secretpassword'
......@@ -4,11 +4,10 @@ const winston = require('winston')
module.exports = {
'pubsweet-server': {
db: {
// database: 'test',
port: 5499,
user: 'testuser',
password: 'testpass',
database: global.__testDbName || 'test',
port: 5460,
user: 'test',
password: 'secretpassword',
database: global.__testDbName || 'editoria_test',
},
enableExperimentalGraphql: true,
logger: new winston.Logger({
......@@ -32,6 +31,12 @@ module.exports = {
},
},
},
pubsweet: {
components: [
'@pubsweet/model-user',
'editoria-data-model/src/customTag',
],
},
schema: {
Manuscript: {
properties: {
......
module.exports = {
setupTestFrameworkScriptFile: '<rootDir>/__tests__/config/jestSetup.js',
testEnvironment: 'jest-environment-db',
testPathIgnorePatterns: [
'<rootDir>/__tests__/config',
'<rootDir>/__tests__/helpers',
'<rootDir>/node_modules/',
'./config',
'./__tests__/helpers',
'./node_modules/',
],
}
......@@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"keywords": [
"pubsweet-component",
......
const NodeEnvironment = require('jest-environment-node')
const pg = require('pg')
// require('../editoria-authsome/test/helpers/jest-setup')
require('../data-model/__tests__/config/jestSetup')
const config = require('config')
const dbConfig = config['pubsweet-server'] && config['pubsweet-server'].db
Object.assign(dbConfig, {
connectionTimeoutMillis: 5000,
idleTimeoutMillis: 1000,
......@@ -14,7 +11,6 @@ Object.assign(dbConfig, {
class DatabaseTestEnvironment extends NodeEnvironment {
async setup() {
// console.log(config)
await super.setup()
this.db = new pg.Client(dbConfig)
// console.log(this.db)
......
......@@ -4,9 +4,6 @@
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
......
......@@ -3,9 +3,6 @@
"version": "0.1.5",
"description": "The navigation for the Editoria project.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"pubsweet-component",
"pubsweet-client"
......
......@@ -4,7 +4,6 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node install"
},
"author": "Yannis Barlas",
......
This diff is collapsed.
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