Skip to content
Snippets Groups Projects
Commit 6e25bc33 authored by Jennifer Spencer's avatar Jennifer Spencer
Browse files

test: abstract authentication for e2e tests into helper file

parent 6a8767bf
No related branches found
No related tags found
1 merge request!40test: abstract authentication for e2e tests into helper file
Pipeline #6480 passed with stages
in 3 minutes and 31 seconds
......@@ -6,5 +6,8 @@
"globals": {
"fixture": true,
"test": true
},
"rules": {
"no-param-reassign": ["error", { "props": false }]
}
}
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 replay from 'replay'
import { Selector, ClientFunction } from 'testcafe'
import { addUser } from '@pubsweet/db-manager'
import authentication from 'pubsweet-server/src/authentication'
import { startServer, setup, teardown } from './helpers/setup'
import { Selector } from 'testcafe'
import { dashboard } from './pageObjects'
import authenticateFixture from './helpers/authenticate-fixture'
replay.fixtures = `${__dirname}/http-mocks`
const admin = {
username: 'tester',
email: 'tester@example.com',
password: 'password',
orcid: '0000-0001',
admin: true,
}
let token
fixture('Submission')
.before(startServer)
.beforeEach(async () => {
await setup()
const user = await addUser(admin)
token = authentication.token.create(user)
})
.afterEach(teardown)
const localStorageSet = ClientFunction((key, val) =>
localStorage.setItem(key, val),
)
const f = fixture('Submission')
authenticateFixture(f)
test('Happy path', async t => {
// fake login by navigating to site and injecting token into local storage
await t.navigateTo(dashboard.url)
await localStorageSet('token', token)
await t.ctx.localStorageSet(t.ctx.token)
await t.navigateTo(dashboard.url).click('[data-test-id=submit]')
......
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