From 371dae7fd434fe98ae6296e8ac765133f2b42b82 Mon Sep 17 00:00:00 2001 From: Juho Haapakoski Date: Fri, 25 Oct 2024 19:06:52 +0300 Subject: [PATCH] AE-2317: Add e2e test to test effects of destroying expired todistukset --- .../vanhentuneiden-tuhoaminen/laatija.cy.js | 54 +++++++++++++++++++ .../energiatodistus/energiatodistukset.svelte | 6 ++- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/laatija.cy.js diff --git a/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/laatija.cy.js b/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/laatija.cy.js new file mode 100644 index 000000000..0b89400a1 --- /dev/null +++ b/e2e-tests/cypress/cypress/e2e/vanhentuneiden-tuhoaminen/laatija.cy.js @@ -0,0 +1,54 @@ +import { FIXTURES } from '../../fixtures/laatija'; + +const baseUrl = Cypress.config('baseUrl'); + +context('Laatija', () => { + beforeEach(() => { + cy.intercept(/\/api\/private/, req => { + req.headers = { ...req.headers, ...FIXTURES.headers }; + }); + cy.resetDb(); + }); + + describe('energiatodistukset', () => { + it('should see energiatodistus before it is expired', async () => { + cy.visit('/#/energiatodistus/all'); + + cy.get('[data-cy="energiatodistus-id"]').contains('1').should('exist'); + cy.get('[data-cy="energiatodistus-id"]') + .contains('1') + .siblings('[data-cy="energiatodistus-tila"]') + .should('have.text', 'Voimassa'); + + const query = + "update etp.energiatodistus set voimassaolo_paattymisaika = now() - interval '2 days' where id = 1;"; + // This does not matter but it needs to be parseable by our database audit system. + const applicationName = '-6@cypress'; + + // Call the Cypress task to execute the query + cy.task('executeQuery', { query, applicationName }); + cy.request( + 'POST', + 'http://localhost:3444/api/internal/energiatodistukset/anonymize-and-delete-expired' + ).then(response => { + expect(response.status).to.eq(200); + }); + + //cy.get('[data-cy="energiatodistus-id"]').contains('1').should('exist'); + + // This is kind of flaky as there is no way to know when the expiration is finished... + + cy.wait(3000); + + cy.reload(); + + cy.get('[data-cy="energiatodistus-id"]').contains('1').should('exist'); + cy.get('[data-cy="energiatodistus-id"]') + .contains('1') + .siblings('[data-cy="energiatodistus-tila"]') + .should('have.text', 'energiatodistus.tila.undefined'); + //TODO: + //cy.get('[data-cy="energiatodistus-id"]').contains('1').siblings('[data-cy="energiatodistus-tila"]').should('not.exist'); + }); + }); +}); diff --git a/etp-front/src/pages/energiatodistus/energiatodistukset.svelte b/etp-front/src/pages/energiatodistus/energiatodistukset.svelte index d95de20ae..ecd318036 100644 --- a/etp-front/src/pages/energiatodistus/energiatodistukset.svelte +++ b/etp-front/src/pages/energiatodistus/energiatodistukset.svelte @@ -339,13 +339,15 @@ data-cy="energiatodistus-row" class="etp-table--tr etp-table--tr__link" on:click={ETViews.toETView(energiatodistus)}> - + {i18n( 'energiatodistus.tila.' + et.tilaKey(energiatodistus['tila-id']) )} - {energiatodistus.id} + + {energiatodistus.id} + {orEmpty(energiatodistus.tulokset['e-luokka'])}