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') })
}
// eslint-disable-next-line no-undef
const env = typeof Cypress !== 'undefined' ? Cypress.env() : process.env
const {
MAPBOX_TOKEN,
JWT_SECRET,
@ -20,7 +23,7 @@ const {
NEO4J_PASSWORD = 'neo4j',
CLIENT_URI = 'http://localhost:3000',
GRAPHQL_URI = 'http://localhost:4000',
} = process.env
} = env
export const requiredConfigs = {
MAPBOX_TOKEN,

View File

@ -34,8 +34,8 @@ Factory.define('userWithoutEmailAddress')
})
Factory.define('user')
.option('email', faker.internet.exampleEmail)
.extend('userWithoutEmailAddress')
.option('email', faker.internet.exampleEmail)
.after(async (buildObject, options) => {
const [user, email] = await Promise.all([
buildObject,
@ -47,7 +47,7 @@ Factory.define('user')
export default function create() {
return {
factory: async ({ args, options }) => {
factory: ({ 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 => {
cy.factory().create('User', {
email: `${role}@example.org`,
password: '1234',
termsAndConditionsAgreedVersion: VERSION,
role
}, {
email: `${role}@example.org`,
password: '1234',
})
cy.login({
email: `${role}@example.org`,
@ -127,7 +128,7 @@ Given('somebody reported the following posts:', table => {
password: '1234'
}
cy.factory()
.create('User', submitter)
.create('User', {}, submitter)
.authenticateAs(submitter)
.mutate(gql`mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
fileReport(resourceId: $resourceId, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription) {

View File

@ -192,11 +192,6 @@ When("I press {string}", label => {
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 => {
cy.factory().create('Category', {
id: `cat-456`,

View File

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