Commit 02cbaee2 authored by Alexandros Georgantas's avatar Alexandros Georgantas

test(app): fixes for seeding, seed scripts, truncate db

parent e675a8c9
describe('Dashboard', () => {
beforeEach(() => {
cy.exec('yarn seed:createBooksWithUsersAndTeams')
cy.exec('node ./scripts/truncateDB.js')
cy.exec('node ./scripts/createBooksWithUsersAndTeams.js')
})
it('shows dashboard', () => {
cy.login('author')
cy.login('admin')
cy.visit('/books')
})
})
......@@ -11,6 +11,10 @@ const checkFormError = message => {
}
describe('Signup page', () => {
beforeEach(() => {
cy.exec('node ./scripts/truncateDB.js')
})
it('loads signup page', () => {
cy.visit('/signup')
cy.contains('Sign up')
......
const credentials = {
admin: {
username: 'admin',
password: '123456789',
password: 'password',
},
user1: {
givenName: 'John Travolta',
......
......@@ -35,12 +35,22 @@ const createBooksWithUsersAndTeams = async () => {
collection = collections[0]
}
let adminUser = await User.findByUsername('admin')
let authorUser = await User.findByUsername('author')
let productionEditorUser = await User.findByUsername('productionEditor')
let globalProductionEditorUser = await User.findByUsername(
'globalProductionEditor',
)
let copyEditorUser = await User.findByUsername('copyEditor')
if (!adminUser) {
adminUser = await new User({
username: 'admin',
email: 'admin@example.com',
password: 'password',
admin: true,
}).save()
}
if (!authorUser) {
authorUser = await new User({
username: 'author',
......
const db = require('@pubsweet/db-manager/src/db')
const truncateDB = async () => {
const { rows } = await db.raw(`
SELECT tablename
FROM pg_tables
WHERE schemaname = current_schema
`)
const truncateQuery = `START TRANSACTION;
${rows.map(row => `TRUNCATE "${row.tablename}" CASCADE`).join(';')};
COMMIT`
await db.raw(truncateQuery)
}
module.exports = truncateDB
truncateDB()
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