From 31d5ca8add3adef0efe35c9c9d8f58236f3640b2 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Thu, 26 Sep 2024 12:53:02 +0200 Subject: [PATCH] implemented test db reset for e2e tests --- cypress.config.js | 5 ++++- cypress/e2e/asAdmin.cy.js | 3 +++ cypress/e2e/misc.cy.js | 5 +++++ cypress/e2e/ui.cy.js | 6 +++++- cypress/e2e/userRights.cy.js | 3 +++ cypress/support/commands.js | 4 ++++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 610f8a38..9e9d7ea4 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,11 +2,14 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { - setupNodeEvents(on, config) { + setupNodeEvents(_on, _config) { // implement node event listeners here }, baseUrl: 'http://localhost:5173/', }, + env: { + backendUrl: "http://backend:4000/test/reset-test-database" + }, viewportHeight: 900, viewportWidth: 1200, }); diff --git a/cypress/e2e/asAdmin.cy.js b/cypress/e2e/asAdmin.cy.js index b87a166b..7d27fd6e 100644 --- a/cypress/e2e/asAdmin.cy.js +++ b/cypress/e2e/asAdmin.cy.js @@ -1,3 +1,6 @@ +before('Reset database', () => { + cy.request(Cypress.env("backendUrl")); +}); describe('Open each page, table view and detail view, and check at least some correct text appears', () => { beforeEach('Login as admin', () => { diff --git a/cypress/e2e/misc.cy.js b/cypress/e2e/misc.cy.js index a570e10a..7e58f248 100644 --- a/cypress/e2e/misc.cy.js +++ b/cypress/e2e/misc.cy.js @@ -21,7 +21,12 @@ const doesNotHaveStagingMode = (viewUrl) => { cy.contains('Edit') } +before('Reset database', () => { + cy.request(Cypress.env("backendUrl")); +}); + describe('Test individual features across the app', () => { + it('Locality update tab opens, detailed modal works, view-link works', () => { cy.visit(`/locality/24750?tab=10`) cy.contains('2006-10-16') diff --git a/cypress/e2e/ui.cy.js b/cypress/e2e/ui.cy.js index 4267a18e..f9f4f506 100644 --- a/cypress/e2e/ui.cy.js +++ b/cypress/e2e/ui.cy.js @@ -3,6 +3,10 @@ Mostly to prove some user stories are complete */ +before('Reset database', () => { + cy.request(Cypress.env("backendUrl")); +}); + describe('Button Tests', () => { it('Buttons for Localities, Species, References, Cross-Search, Map & Time Units are visible', () => { cy.visit('/') @@ -89,4 +93,4 @@ describe('Button Tests', () => { cy.contains('Locality Species').should('be.visible') cy.contains('Updates').should('be.visible') }) - }) \ No newline at end of file + }) diff --git a/cypress/e2e/userRights.cy.js b/cypress/e2e/userRights.cy.js index 513d742f..b93f2b2a 100644 --- a/cypress/e2e/userRights.cy.js +++ b/cypress/e2e/userRights.cy.js @@ -1,3 +1,6 @@ +before('Reset database', () => { + cy.request(Cypress.env("backendUrl")); +}); describe('Broadly test what different user rights see', () => { describe('Admin visibility', () => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index fb8599bd..58433c27 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -38,3 +38,7 @@ Cypress.Commands.add('pageForbidden', (url) => { cy.visit(url) cy.contains('Your user is not authorized to view this page.') }) + +Cypress.Commands.add("resetDatabase", () => { + cy.task("resetDatabase") +})