Commit 8865a438 authored by Jennifer Spencer's avatar Jennifer Spencer
Browse files

refactor: alter setup to override fixture.beforeEach with test.before in e2e login test

parent 724036a2
import { ClientFunction } from 'testcafe'
import { addUser } from '@pubsweet/db-manager'
import authentication from 'pubsweet-server/src/authentication'
import { startServer, setup, teardown } from './setup'
const admin = {
username: 'tester',
email: 'tester@example.com',
password: 'password',
orcid: '0000-0001',
admin: true,
}
export default chosenFixture =>
chosenFixture
.before(startServer)
.beforeEach(async t => {
await setup()
const user = await addUser(admin)
t.ctx.token = authentication.token.create(user)
t.ctx.localStorageSet = ClientFunction(token =>
localStorage.setItem('token', token),
)
})
.afterEach(teardown)
import { startServer, setup, teardown } from './setup'
export default chosenFixture =>
chosenFixture
.before(startServer)
.beforeEach(setup)
.afterEach(teardown)
import { createTables } from '@pubsweet/db-manager'
import { ClientFunction } from 'testcafe'
import DestinationRequest from 'testcafe-hammerhead/lib/request-pipeline/destination-request'
import { addUser, createTables } from '@pubsweet/db-manager'
import start from 'pubsweet/src/startup/start'
import authentication from 'pubsweet-server/src/authentication'
// import start from 'pubsweet-server'
let server
const admin = {
username: 'tester',
email: 'tester@example.com',
password: 'password',
orcid: '0000-0001',
admin: true,
}
export async function startServer() {
if (!server) {
// increase timeout to wait for webpack compilation
......@@ -13,8 +23,13 @@ export async function startServer() {
}
}
export function setup() {
return createTables(true)
export async function setup(t) {
await createTables(true)
const user = await addUser(admin)
t.ctx.token = authentication.token.create(user)
t.ctx.localStorageSet = ClientFunction(token =>
localStorage.setItem('token', token),
)
}
export function teardown() {}
import { ClientFunction } from 'testcafe'
import { dashboard } from './pageObjects'
import authenticateFixture from './helpers/authenticate-fixture'
import setFixtureHooks from './helpers/set-fixture-hooks'
import mockOrcid from './helpers/mock-orcid'
import { setup } from './helpers/setup'
const f = fixture('Submission')
authenticateFixture(f)
setFixtureHooks(f)
const getTokenFromLocalStorage = ClientFunction(() =>
localStorage.getItem('token'),
)
test.before(mockOrcid)('Login successful', async t => {
test.before(async t => {
await setup(t)
return mockOrcid()
})('Login successful', async t => {
await t.navigateTo(dashboard.url).click('[href="/auth/orcid"]')
await t.expect(getTokenFromLocalStorage()).typeOf('string')
......
import replay from 'replay'
import { Selector } from 'testcafe'
import { dashboard, authorDetails } from './pageObjects'
import authenticateFixture from './helpers/authenticate-fixture'
import setFixtureHooks from './helpers/set-fixture-hooks'
replay.fixtures = `${__dirname}/http-mocks`
const f = fixture('Submission')
authenticateFixture(f)
setFixtureHooks(f)
test('Happy path', async t => {
// fake login by navigating to site and injecting token into local storage
......
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