From a024282f757e3bcebf0557bef82df499959ca344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Thu, 21 Feb 2019 22:08:37 +0100 Subject: [PATCH] Implement first cucumber features with factories --- .gitignore | 1 + cypress.env.template.json | 5 ++++ cypress/integration/06.WritePost.feature | 2 +- cypress/integration/common/steps.js | 23 +++++++++++++----- cypress/support/factories.js | 30 ++++++++++++++++++++++++ cypress/support/index.js | 1 + 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 cypress.env.template.json create mode 100644 cypress/support/factories.js diff --git a/.gitignore b/.gitignore index 0de8272fc..52fe4effc 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,4 @@ static/uploads cypress/videos cypress/screenshots/ +cypress.env.json diff --git a/cypress.env.template.json b/cypress.env.template.json new file mode 100644 index 000000000..59cf04ab6 --- /dev/null +++ b/cypress.env.template.json @@ -0,0 +1,5 @@ +{ + "NEO4J_URI": "bolt://localhost:7687", + "NEO4J_USERNAME": "neo4j", + "NEO4J_PASSWORD": "letmein" +} diff --git a/cypress/integration/06.WritePost.feature b/cypress/integration/06.WritePost.feature index e889a4783..a9cb81ff9 100644 --- a/cypress/integration/06.WritePost.feature +++ b/cypress/integration/06.WritePost.feature @@ -5,7 +5,7 @@ Feature: Create a post Background: Given I am logged in - Given I am on the "landing" page + And I am on the "landing" page Scenario: Create a post When I click on the big plus icon in the bottom right corner to create post diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index fadee974b..fcc2c2789 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -6,9 +6,18 @@ import users from '../../fixtures/users.json' let lastPost = { } +let loginCredentials Given('I am logged in', () => { - cy.loginAs('admin') + loginCredentials = { + email: 'admin@example.org', + password: '1234', + } + cy.factory().create('user', { + role: 'admin', + ...loginCredentials + }) + cy.login('admin@example.org', '1234') }) Given('I am logged in as {string}', userType => { cy.loginAs(userType) @@ -112,7 +121,9 @@ When('I click on the big plus icon in the bottom right corner to create post', ( }) Given('I previously created a post', () => { - // TODO: create a post in the database + cy.factory() + .authenticateAs(loginCredentials) + .create('post', lastPost) }) When('I choose {string} as the title of the post', (title) => { @@ -121,15 +132,15 @@ When('I choose {string} as the title of the post', (title) => { }) When('I type in the following text:', (text) => { - lastPost.text = text.replace('\n', ' ') - cy.get('.ProseMirror').type(lastPost.text) + lastPost.content = text.replace('\n', ' ') + cy.get('.ProseMirror').type(lastPost.content) }) Then('the post shows up on the landing page at position {int}', (index) => { cy.openPage('landing') const selector = `:nth-child(${index}) > .ds-card > .ds-card-content` cy.get(selector).should('contain', lastPost.title) - cy.get(selector).should('contain', lastPost.text) + cy.get(selector).should('contain', lastPost.content) }) Then('I get redirected to {string}', (route) => { @@ -138,5 +149,5 @@ Then('I get redirected to {string}', (route) => { Then('the post was saved successfully', () => { cy.get('.ds-card-header > .ds-heading').should('contain', lastPost.title) - cy.get('.content').should('contain', lastPost.text) + cy.get('.content').should('contain', lastPost.content) }) diff --git a/cypress/support/factories.js b/cypress/support/factories.js new file mode 100644 index 000000000..c56f6bf27 --- /dev/null +++ b/cypress/support/factories.js @@ -0,0 +1,30 @@ +// TODO: find a better way how to import the factories +import Factory from '../../../Nitro-Backend/src/seed/factories' +import { getDriver } from '../../../Nitro-Backend/src/bootstrap/neo4j' + +const neo4jDriver = getDriver({ + uri: Cypress.env('NEO4J_URI'), + username: Cypress.env('NEO4J_USERNAME'), + password: Cypress.env('NEO4J_PASSWORD') +}) +const factory = Factory({neo4jDriver}) + +beforeEach(async () => { + await factory.cleanDatabase({ neo4jDriver }) +}) + +Cypress.Commands.add('factory', (node, relationship, properties) => { + return Factory() +}) + +Cypress.Commands.add('create', { prevSubject: true }, (factory, node, properties) => { + return factory.create(node, properties) +}) + +Cypress.Commands.add('relate', { prevSubject: true }, (factory, node, relationship, properties) => { + return factory.relate(node, relationship, properties) +}) + +Cypress.Commands.add('authenticateAs', { prevSubject: true }, (factory, node, relationship, properties) => { + return factory.authenticateAs(node, relationship, properties) +}) diff --git a/cypress/support/index.js b/cypress/support/index.js index d68db96df..3519487bf 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -15,6 +15,7 @@ // Import commands.js using ES2015 syntax: import './commands' +import './factories' // Alternatively you can use CommonJS syntax: // require('./commands')