Commit 1c50b431 authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

fix(test): make them run after pubsweet upgrade

parent 8868af9c
const registerComponents = require('./helpers/registerComponents')
registerComponents(['book', 'bookCollection', 'division'])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
const config = require('config')
const set = require('lodash/set')
// const set = require('lodash/set')
const unset = require('lodash/unset')
const { Book, BookCollection, Division } = require('../src').models
......@@ -16,7 +13,7 @@ describe('Book', () => {
it('can add books', async () => {
const divisionId = uuid()
const publicationDate = new Date()
const publicationDate = new Date().toString()
let collectionId
await new BookCollection().save().then(res => (collectionId = res.id))
......@@ -40,16 +37,10 @@ describe('Book', () => {
})
it('creates divisions on book creation based on the config', async () => {
set(config, 'bookBuilder.divisions', [
{ name: 'front' },
{ name: 'body' },
{ name: 'back' },
])
const collection = await new BookCollection().save()
const book = await new Book({ collectionId: collection.id }).save()
const divisions = await Division.query().where('bookId', book.id)
const divisions = await Division.query().where('bookId', book.id)
expect(divisions).toHaveLength(3)
expect(book.divisions).toHaveLength(3)
......@@ -66,11 +57,10 @@ describe('Book', () => {
const actualPosition = book.divisions.indexOf(division.id)
expect(actualPosition).toBe(correctPosition)
})
unset(config, 'bookBuilder')
})
it('creates a default division on book creation if no config is found', async () => {
unset(config, 'bookBuilder')
const collection = await new BookCollection().save()
const book = await new Book({ collectionId: collection.id }).save()
const divisions = await Division.query().where('bookId', book.id)
......
const registerComponents = require('./helpers/registerComponents')
registerComponents(['book', 'bookCollection'])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
const { Book, BookCollection } = require('../src').models
......
const registerComponents = require('./helpers/registerComponents')
registerComponents(['bookCollection', 'bookCollectionTranslation'])
const { dbCleaner } = require('pubsweet-server/test')
const { BookCollection, BookCollectionTranslation } = require('../src').models
......
const registerComponents = require('./helpers/registerComponents')
registerComponents(['book', 'bookCollection', 'bookComponent', 'division'])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
const {
......
const registerComponents = require('./helpers/registerComponents')
registerComponents([
'book',
'bookCollection',
'bookComponent',
'bookComponentState',
'division',
])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
......
const registerComponents = require('./helpers/registerComponents')
registerComponents([
'book',
'bookCollection',
'bookComponent',
'bookComponentTranslation',
'division',
])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
......
const registerComponents = require('./helpers/registerComponents')
registerComponents(['book', 'bookTranslation', 'bookCollection'])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
......
const registerComponents = require('./helpers/registerComponents')
registerComponents(['book', 'bookCollection', 'division'])
const uuid = require('uuid/v4')
const { dbCleaner } = require('pubsweet-server/test')
const { Book, BookCollection, Division } = require('../src').models
......
const path = require('path')
/*
Registers an array of components on pubsweet's config, so that the migrations
are ran. Will treat a string as a single component.
Valid input examples:
- ['book', 'bookCollection']
- 'book'
Only works for this package, as it assumes a specific structure to locate
the different models.
*/
const registerComponents = componentNames => {
let components = componentNames
const paths = []
if (typeof componentNames === 'string') {
components = [componentNames]
} else if (!Array.isArray(componentNames)) {
throw new Error('Component names need to be an array or a string')
}
components.forEach(comp => {
const componentPath = path.resolve(__dirname, '..', '..', 'src', comp)
paths.push(componentPath)
})
const toString = paths.map(p => `"${p}"`).join(', ')
// console.log(`{"pubsweet":{"components":[${toString}]}}`)
// return `{"pubsweet":{"components":[${toString}]}}`
process.env.NODE_CONFIG = `{"pubsweet":{"components":[${toString}]}}`
}
module.exports = registerComponents
const { User } = require('pubsweet-server')
const registerComponents = require('./helpers/registerComponents')
registerComponents(['bookCollection', 'lock'])
const {
editoriaDataModel: {
models: { User },
},
} = require('editoria-data-model')
const { BookCollection, Lock } = require('editoria-data-model/src').models
const { dbCleaner } = require('pubsweet-server/test')
const { BookCollection, Lock } = require('../src').models
let collection, user
describe('Lock', () => {
......
......@@ -2,3 +2,4 @@ export DB_PORT='5460'
export DB_NAME='editoria_test'
export DB_USER='test'
export DB_PASSWORD='secretpassword'
export ALLOW_CONFIG_MUTATIONS=true
......@@ -31,10 +31,27 @@ module.exports = {
},
},
},
bookBuilder: {
divisions: [{ name: 'front' }, { name: 'body' }, { name: 'back' }],
},
pubsweet: {
components: [
'@pubsweet/model-user',
'@pubsweet/model-team',
'editoria-data-model/src/book',
'editoria-data-model/src/lock',
'editoria-data-model/src/bookCollection',
'editoria-data-model/src/bookCollectionTranslation',
'editoria-data-model/src/bookComponent',
'editoria-data-model/src/bookComponentState',
'editoria-data-model/src/bookComponentTranslation',
'editoria-data-model/src/bookTranslation',
'editoria-data-model/src/customTag',
'editoria-data-model/src/division',
'editoria-data-model/src/team',
'editoria-data-model/src/user',
'editoria-data-model/src/dataloader',
'editoria-api',
],
},
schema: {
......
process.env.ALLOW_CONFIG_MUTATIONS = true
const NodeEnvironment = require('jest-environment-node')
const pg = require('pg')
const config = require('config')
......
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