From bcc4b5289b73538c759880da3c0529a8cb57f730 Mon Sep 17 00:00:00 2001 From: Juho Haapakoski Date: Tue, 29 Oct 2024 14:07:33 +0200 Subject: [PATCH] AE-2316: Remove querying the database from e2e tests The expired todistukset are just added to the test data --- e2e-tests/cypress/cypress.config.js | 25 +--- .../todistusten-tuhoaminen.cy.js | 126 ++++++---------- e2e-tests/cypress/package-lock.json | 135 ------------------ e2e-tests/cypress/package.json | 3 - 4 files changed, 46 insertions(+), 243 deletions(-) diff --git a/e2e-tests/cypress/cypress.config.js b/e2e-tests/cypress/cypress.config.js index 2b10f52e0..296218276 100644 --- a/e2e-tests/cypress/cypress.config.js +++ b/e2e-tests/cypress/cypress.config.js @@ -1,5 +1,4 @@ const { defineConfig } = require('cypress'); -const pg = require('pg'); module.exports = defineConfig({ viewportHeight: 900, @@ -10,28 +9,6 @@ module.exports = defineConfig({ backendUrl: 'http://localhost:3444', publicUrl: 'http://localhost:5059', baseUrl: 'https://localhost:3009', - setupNodeEvents(on, config) { - on('task', { - // applicationName needs to be parsable by our database audit system. For example -6@something. - executeQuery({ query, applicationName }) { - const client = new pg.Client({ - connectionString: `postgresql://etp_app:etp@localhost:5444/etp_dev?search_path=etp&application_name=${applicationName}` - }); - - return client - .connect() - .then(() => client.query(query)) - .then(result => { - return result.rows; - }) - .catch(err => { - throw err; - }) - .finally(() => { - client.end(); - }); - } - }); - } + setupNodeEvents(on, config) {} } }); diff --git a/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/todistusten-tuhoaminen.cy.js b/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/todistusten-tuhoaminen.cy.js index 9d4eda437..69b14a669 100644 --- a/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/todistusten-tuhoaminen.cy.js +++ b/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/todistusten-tuhoaminen.cy.js @@ -6,21 +6,27 @@ const backendUrl = Cypress.config('backendUrl'); const expiredEtWithValvontaId = 7; const expiredEtWithoutValvontaId = 6; -const etToBeMadeExpiredId = 1; -const signedEtThatWillNotBeTouchedId = 4; +const signedEtThatWillNotBeTouched1 = 1; +const signedEtThatWillNotBeTouchedId2 = 4; + +const runExpirationOfTodistukset = () => { + cy.request( + 'POST', + `${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired` + ).then(response => { + expect(response.status).to.eq(200); + }); + // There is no way to know when running the expiration is finished. + cy.wait(1000); +}; // Only thing about applicationName that matters in this case is that it is parseable by the audit system. // Now just put as @cypress. const applicationName = '-6@cypress'; context('Laatija', () => { - // Using just `before` here as we do not want to reset the database in - // between tests. - before(() => { - cy.resetDb(); - }); - beforeEach(() => { + cy.resetDb(); cy.intercept(/\/api\/private/, req => { req.headers = { ...req.headers, ...FIXTURES.headers }; }); @@ -31,12 +37,12 @@ context('Laatija', () => { cy.visit('/#/energiatodistus/all'); cy.get('[data-cy="energiatodistus-id"]') - .contains(etToBeMadeExpiredId) + .contains(signedEtThatWillNotBeTouched1) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); cy.get('[data-cy="energiatodistus-id"]') - .contains(signedEtThatWillNotBeTouchedId) + .contains(signedEtThatWillNotBeTouchedId2) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); @@ -51,33 +57,27 @@ context('Laatija', () => { .should('have.text', 'Voimassa'); }); - it('set the et 1 as expired and run expiration', () => { - const query = - "update etp.energiatodistus set voimassaolo_paattymisaika = now() - interval '2 days' where id = 1;"; - - cy.task('executeQuery', { query, applicationName }).then(() => { - cy.request( - 'POST', - `${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired` - ).then(response => { - expect(response.status).to.eq(200); - }); + it('Should only see non-expired and expired with ongoing valvonta energiatodistukset after running expiration', () => { + cy.request( + 'POST', + `${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired` + ).then(response => { + expect(response.status).to.eq(200); }); + // There is no way to know when running the expiration is finished. cy.wait(1000); - }); - it('Should only see non-expired and expired with ongoing valvonta energiatodistukset', () => { cy.visit('/#/energiatodistus/all'); cy.get('[data-cy="energiatodistus-id"]') - .contains(signedEtThatWillNotBeTouchedId) + .contains(signedEtThatWillNotBeTouchedId2) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); cy.get('[data-cy="energiatodistus-id"]') - .contains(etToBeMadeExpiredId) - .should('not.exist'); + .contains(signedEtThatWillNotBeTouched1) + .should('exist'); cy.get('[data-cy="energiatodistus-id"]') .contains(expiredEtWithoutValvontaId) @@ -87,14 +87,10 @@ context('Laatija', () => { .contains(expiredEtWithValvontaId) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Vanhentunut'); - }); - it('energiatodistus with valvonta can be still accessed', () => { cy.visit(`/#/energiatodistus/2018/${expiredEtWithValvontaId}`); cy.contains('Energiatodistus 2018/7 - Vanhentunut').should('exist'); - }); - it('energiatodistus without valvonta can not be accessed', () => { cy.visit(`/#/energiatodistus/2018/${expiredEtWithoutValvontaId}`); cy.contains('Puutteelliset käyttöoikeudet').should('exist'); }); @@ -102,11 +98,8 @@ context('Laatija', () => { }); context('Paakayttaja', () => { - before(() => { - cy.resetDb(); - }); - beforeEach(() => { + cy.resetDb(); cy.intercept(/\/api\/private/, req => { req.headers = { ...req.headers, ...paakayttajaHeaders }; }); @@ -117,7 +110,7 @@ context('Paakayttaja', () => { cy.visit('/#/energiatodistus/all'); cy.get('[data-cy="energiatodistus-id"]') - .contains(etToBeMadeExpiredId) + .contains(signedEtThatWillNotBeTouched1) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); @@ -136,30 +129,17 @@ context('Paakayttaja', () => { .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); }); - it('running the expiration should succeed', () => { - const query = - "update etp.energiatodistus set voimassaolo_paattymisaika = now() - interval '2 days' where id = 1;"; - cy.task('executeQuery', { query, applicationName }).then(() => { - cy.request( - 'POST', - `${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired` - ).then(response => { - expect(response.status).to.eq(200); - }); - }); - // There is no way to know when running the expiration is finished. - cy.wait(1000); - }); - it('should see 1 and 6 as tuhottu, 4 as voimassa and 7 as vahentunut', () => { + it('should see 1 and 6 as tuhottu, 4 as voimassa and 7 as vahentunut after running the expiration', () => { + runExpirationOfTodistukset(); cy.visit('/#/energiatodistus/all'); cy.get('[data-cy="energiatodistus-id"]') - .contains(etToBeMadeExpiredId) + .contains(signedEtThatWillNotBeTouched1) .siblings('[data-cy="energiatodistus-tila"]') - .should('have.text', 'Tuhottu'); + .should('have.text', 'Voimassa'); cy.get('[data-cy="energiatodistus-id"]') - .contains(signedEtThatWillNotBeTouchedId) + .contains(signedEtThatWillNotBeTouchedId2) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Voimassa'); @@ -172,16 +152,12 @@ context('Paakayttaja', () => { .contains(expiredEtWithValvontaId) .siblings('[data-cy="energiatodistus-tila"]') .should('have.text', 'Vanhentunut'); - }); - it('energiatodistus without valvonta can not be accessed', () => { - cy.visit('/#/energiatodistus/all'); + cy.get('[data-cy="energiatodistus-id"]') .contains(expiredEtWithoutValvontaId) .click(); cy.contains('Puutteelliset käyttöoikeudet').should('exist'); - }); - it('energiatodistus with valvonta can still be accessed', () => { cy.visit('/#/energiatodistus/all'); cy.get('[data-cy="energiatodistus-id"]') .contains(expiredEtWithValvontaId) @@ -192,7 +168,7 @@ context('Paakayttaja', () => { }); context('Public', () => { - before(() => { + beforeEach(() => { cy.resetDb(); }); @@ -212,28 +188,15 @@ context('Public', () => { .should('exist'); cy.get('[data-cy="ethaku-tunnus"]') - .contains(signedEtThatWillNotBeTouchedId) + .contains(signedEtThatWillNotBeTouchedId2) .should('exist'); cy.get('[data-cy="ethaku-tunnus"]') - .contains(etToBeMadeExpiredId) + .contains(signedEtThatWillNotBeTouched1) .should('exist'); }); - it('running the expiration should succeed', () => { - const query = - "update etp.energiatodistus set voimassaolo_paattymisaika = now() - interval '2 days' where id = 1;"; - cy.task('executeQuery', { query, applicationName }).then(() => { - cy.request( - 'POST', - `${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired` - ).then(response => { - expect(response.status).to.eq(200); - }); - }); - // There is no way to know when running the expiration is finished. - cy.wait(1000); - }); - it('should only see the not expired todistus.', () => { + it('should only see the non-expired todistukset after running the expiration.', () => { + runExpirationOfTodistukset(); cy.visit(`${publicUrl}/ethaku`); cy.get('[data-cy="ethaku-hae"]').click(); @@ -248,12 +211,12 @@ context('Public', () => { .should('not.exist'); cy.get('[data-cy="ethaku-tunnus"]') - .contains(signedEtThatWillNotBeTouchedId) + .contains(signedEtThatWillNotBeTouchedId2) .should('exist'); cy.get('[data-cy="ethaku-tunnus"]') - .contains(etToBeMadeExpiredId) - .should('not.exist'); + .contains(signedEtThatWillNotBeTouched1) + .should('exist'); cy.visit( `${publicUrl}/energiatodistus?id=${expiredEtWithValvontaId}&versio=2018` @@ -266,9 +229,10 @@ context('Public', () => { cy.contains('Energiatodistusta ei löytynyt').should('exist'); cy.visit( - `${publicUrl}/energiatodistus?id=${etToBeMadeExpiredId}&versio=2013` + `${publicUrl}/energiatodistus?id=${signedEtThatWillNotBeTouched1}&versio=2013` ); - cy.contains('Energiatodistusta ei löytynyt').should('exist'); + // This is a piece of the todistus' notes. + cy.contains('Seuraavia toimenpiteitä voisi tehdä:').should('exist'); }); }); }); diff --git a/e2e-tests/cypress/package-lock.json b/e2e-tests/cypress/package-lock.json index 6421856f6..106b12cb8 100644 --- a/e2e-tests/cypress/package-lock.json +++ b/e2e-tests/cypress/package-lock.json @@ -8,9 +8,6 @@ "name": "Energiatodistuspalvelu E2E", "version": "0.0.1", "license": "EUPL v1.2", - "dependencies": { - "pg": "^8.13.1" - }, "devDependencies": { "cypress": "^13.6.4", "prettier": "3.3.3" @@ -1454,87 +1451,6 @@ "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, - "node_modules/pg": { - "version": "8.13.1", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.1.tgz", - "integrity": "sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ==", - "dependencies": { - "pg-connection-string": "^2.7.0", - "pg-pool": "^3.7.0", - "pg-protocol": "^1.7.0", - "pg-types": "^2.1.0", - "pgpass": "1.x" - }, - "engines": { - "node": ">= 8.0.0" - }, - "optionalDependencies": { - "pg-cloudflare": "^1.1.1" - }, - "peerDependencies": { - "pg-native": ">=3.0.1" - }, - "peerDependenciesMeta": { - "pg-native": { - "optional": true - } - } - }, - "node_modules/pg-cloudflare": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz", - "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==", - "optional": true - }, - "node_modules/pg-connection-string": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", - "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==" - }, - "node_modules/pg-int8": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", - "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/pg-pool": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.7.0.tgz", - "integrity": "sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==", - "peerDependencies": { - "pg": ">=8.0" - } - }, - "node_modules/pg-protocol": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.7.0.tgz", - "integrity": "sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==" - }, - "node_modules/pg-types": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", - "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", - "dependencies": { - "pg-int8": "1.0.1", - "postgres-array": "~2.0.0", - "postgres-bytea": "~1.0.0", - "postgres-date": "~1.0.4", - "postgres-interval": "^1.1.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/pgpass": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", - "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", - "dependencies": { - "split2": "^4.1.0" - } - }, "node_modules/pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", @@ -1544,41 +1460,6 @@ "node": ">=0.10.0" } }, - "node_modules/postgres-array": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", - "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", - "engines": { - "node": ">=4" - } - }, - "node_modules/postgres-bytea": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", - "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/postgres-date": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", - "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/postgres-interval": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", - "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", - "dependencies": { - "xtend": "^4.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/prettier": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", @@ -1828,14 +1709,6 @@ "node": ">=8" } }, - "node_modules/split2": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", - "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", - "engines": { - "node": ">= 10.x" - } - }, "node_modules/sshpk": { "version": "1.18.0", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", @@ -2092,14 +1965,6 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true }, - "node_modules/xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "engines": { - "node": ">=0.4" - } - }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/e2e-tests/cypress/package.json b/e2e-tests/cypress/package.json index 74906b521..b8ea53587 100644 --- a/e2e-tests/cypress/package.json +++ b/e2e-tests/cypress/package.json @@ -11,8 +11,5 @@ "devDependencies": { "cypress": "^13.6.4", "prettier": "3.3.3" - }, - "dependencies": { - "pg": "^8.13.1" } }