From 447b19eea03f14391be6208d9aecb3ffcff3d068 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 20 Feb 2020 10:52:36 +0100 Subject: [PATCH] Use cy.exec() to talk to the database - Cypress says "To talk to your database or server you need to use the cy.exec(), cy.task(), or cy.request() commands. That means you will need to expose a way to seed and setup your database." https://docs.cypress.io/guides/references/trade-offs.html#Inside-the-browser --- cypress/integration/common/steps.js | 20 ++++++++++---------- cypress/support/factories.js | 8 +------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index f411efa90..412c75e71 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -238,16 +238,16 @@ Given("we have the following comments in our database:", table => { }); Given("we have the following posts in our database:", table => { - table.hashes().forEach((attributesOrOptions, i) => { - cy.factory().build("post", { - ...attributesOrOptions, - deleted: Boolean(attributesOrOptions.deleted), - disabled: Boolean(attributesOrOptions.disabled), - pinned: Boolean(attributesOrOptions.pinned), - }, { - ...attributesOrOptions, - }); - }) + table.hashes().forEach((attributesOrOptions, i) => { + cy.factory().build("post", { + ...attributesOrOptions, + deleted: Boolean(attributesOrOptions.deleted), + disabled: Boolean(attributesOrOptions.disabled), + pinned: Boolean(attributesOrOptions.pinned), + }, { + ...attributesOrOptions, + }); + }) }) Then("I see a success message:", message => { diff --git a/cypress/support/factories.js b/cypress/support/factories.js index 5fac00759..483a83950 100644 --- a/cypress/support/factories.js +++ b/cypress/support/factories.js @@ -9,13 +9,7 @@ const neo4jConfigs = { } const neodeInstance = getNeode(neo4jConfigs) -export const cleanDatabase = () => { - return new Cypress.Promise((resolve, _reject) => { - return neodeInstance.cypher(' MATCH (everything) DETACH DELETE everything;') - .then(() => resolve()) - }) -} -beforeEach(() => cleanDatabase()) +beforeEach(() => cy.exec('yarn run db:reset')) Cypress.Commands.add('neode', () => { return neodeInstance