Fix factories for cypress tests

This commit is contained in:
roschaefer 2020-01-28 02:23:00 +01:00
parent 2a79c53765
commit 094fa196e6
5 changed files with 12 additions and 21 deletions

View File

@ -4,6 +4,9 @@ if (require.resolve) {
dotenv.config({ path: require.resolve('../../.env') }) dotenv.config({ path: require.resolve('../../.env') })
} }
// eslint-disable-next-line no-undef
const env = typeof Cypress !== 'undefined' ? Cypress.env() : process.env
const { const {
MAPBOX_TOKEN, MAPBOX_TOKEN,
JWT_SECRET, JWT_SECRET,
@ -20,7 +23,7 @@ const {
NEO4J_PASSWORD = 'neo4j', NEO4J_PASSWORD = 'neo4j',
CLIENT_URI = 'http://localhost:3000', CLIENT_URI = 'http://localhost:3000',
GRAPHQL_URI = 'http://localhost:4000', GRAPHQL_URI = 'http://localhost:4000',
} = process.env } = env
export const requiredConfigs = { export const requiredConfigs = {
MAPBOX_TOKEN, MAPBOX_TOKEN,

View File

@ -34,8 +34,8 @@ Factory.define('userWithoutEmailAddress')
}) })
Factory.define('user') Factory.define('user')
.option('email', faker.internet.exampleEmail)
.extend('userWithoutEmailAddress') .extend('userWithoutEmailAddress')
.option('email', faker.internet.exampleEmail)
.after(async (buildObject, options) => { .after(async (buildObject, options) => {
const [user, email] = await Promise.all([ const [user, email] = await Promise.all([
buildObject, buildObject,
@ -47,7 +47,7 @@ Factory.define('user')
export default function create() { export default function create() {
return { return {
factory: async ({ args, options }) => { factory: ({ args, options }) => {
return Factory.build('user', args, options) return Factory.build('user', args, options)
}, },
} }

View File

@ -31,10 +31,11 @@ Given("I see David Irving's post on the post page", page => {
Given('I am logged in with a {string} role', role => { Given('I am logged in with a {string} role', role => {
cy.factory().create('User', { cy.factory().create('User', {
email: `${role}@example.org`,
password: '1234',
termsAndConditionsAgreedVersion: VERSION, termsAndConditionsAgreedVersion: VERSION,
role role
}, {
email: `${role}@example.org`,
password: '1234',
}) })
cy.login({ cy.login({
email: `${role}@example.org`, email: `${role}@example.org`,
@ -127,7 +128,7 @@ Given('somebody reported the following posts:', table => {
password: '1234' password: '1234'
} }
cy.factory() cy.factory()
.create('User', submitter) .create('User', {}, submitter)
.authenticateAs(submitter) .authenticateAs(submitter)
.mutate(gql`mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) { .mutate(gql`mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
fileReport(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) { fileReport(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) {

View File

@ -192,11 +192,6 @@ When("I press {string}", label => {
cy.contains(label).click(); cy.contains(label).click();
}); });
Given("we have this user in our database:", table => {
const [firstRow] = table.hashes()
cy.factory().create('User', firstRow)
})
Given("we have the following posts in our database:", table => { Given("we have the following posts in our database:", table => {
cy.factory().create('Category', { cy.factory().create('Category', {
id: `cat-456`, id: `cat-456`,

View File

@ -40,17 +40,9 @@ Cypress.Commands.add('factory', () => {
Cypress.Commands.add( Cypress.Commands.add(
'create', 'create',
{ prevSubject: true }, { prevSubject: true },
async (factory, node, properties) => { async (factory, node, properties, options) => {
await factory.create(node, properties) await factory.create(node, properties, options)
return factory return factory
} }
) )
Cypress.Commands.add(
'relate',
{ prevSubject: true },
async (factory, node, relationship, properties) => {
await factory.relate(node, relationship, properties)
return factory
}
)