diff --git a/e2e-tests/cypress/cypress.config.js b/e2e-tests/cypress/cypress.config.js index f70ed4fce..2b10f52e0 100644 --- a/e2e-tests/cypress/cypress.config.js +++ b/e2e-tests/cypress/cypress.config.js @@ -8,6 +8,7 @@ module.exports = defineConfig({ video: true, e2e: { backendUrl: 'http://localhost:3444', + publicUrl: 'http://localhost:5059', baseUrl: 'https://localhost:3009', setupNodeEvents(on, config) { on('task', { 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 693d2262a..6a6e99bb7 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 @@ -1,7 +1,7 @@ import { FIXTURES } from '../../fixtures/laatija'; import paakayttajaHeaders from '../../fixtures/users/paakayttaja.json'; -const baseUrl = Cypress.config('baseUrl'); +const publicUrl = Cypress.config('publicUrl'); const backendUrl = Cypress.config('backendUrl'); const expiredEtWithValvontaId = 7; @@ -190,3 +190,91 @@ context('Paakayttaja', () => { }); }); }); + +context('Public', () => { + before(() => { + cy.resetDb(); + }); + + beforeEach(() => { + cy.intercept(/\/api\/private/, req => { + req.headers = { ...req.headers, ...paakayttajaHeaders }; + }); + }); + + describe.only('when destroying expired energiatodistukset', () => { + it('should see all the Voimassa energiatodistukset before running the expiration', () => { + cy.visit(`${publicUrl}/ethaku`); + + cy.get('[data-cy="ethaku-hae"]').click(); + + // Notice that these are the type that are seen by the public + cy.get('[data-cy="ethaku-tunnus"]') + .contains(expiredEtWithValvontaId) + .should('exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(expiredEtWithoutValvontaId) + .should('exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(signedEtThatWillNotBeTouchedId) + .should('exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(etToBeMadeExpiredId) + .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.', () => { + cy.visit(`${publicUrl}/ethaku`); + + cy.get('[data-cy="ethaku-hae"]').click(); + + // Notice that these are the type that are seen by the public + cy.get('[data-cy="ethaku-tunnus"]') + .contains(expiredEtWithValvontaId) + .should('not.exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(expiredEtWithoutValvontaId) + .should('not.exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(signedEtThatWillNotBeTouchedId) + .should('exist'); + + cy.get('[data-cy="ethaku-tunnus"]') + .contains(etToBeMadeExpiredId) + .should('not.exist'); + + cy.visit( + `${publicUrl}/energiatodistus?id=${expiredEtWithValvontaId}&versio=2018` + ); + cy.contains('Energiatodistusta ei löytynyt').should('exist'); + + cy.visit( + `${publicUrl}/energiatodistus?id=${expiredEtWithoutValvontaId}&versio=2018` + ); + cy.contains('Energiatodistusta ei löytynyt').should('exist'); + + cy.visit( + `${publicUrl}/energiatodistus?id=${etToBeMadeExpiredId}&versio=2013` + ); + cy.contains('Energiatodistusta ei löytynyt').should('exist'); + }); + }); +}); diff --git a/e2e-tests/cypress/docker-compose.yml b/e2e-tests/cypress/docker-compose.yml index 1bc78e4c7..684727114 100644 --- a/e2e-tests/cypress/docker-compose.yml +++ b/e2e-tests/cypress/docker-compose.yml @@ -64,6 +64,24 @@ services: ports: - 127.0.0.1:3009:3009 + frontend-public: + build: + context: ../../etp-public + dockerfile: e2e.Dockerfile + environment: + WEBPACK_PROXY_TARGET: http://backend:8080 + WEBPACK_ALLOWED_HOSTS: auto + WEBPACK_HOST: 0.0.0.0 + WEBPACK_PORT: 5059 + healthcheck: + test: curl -k http://localhost:5059 || exit 1 + interval: 10s + timeout: 10s + retries: 20 + start_period: 0m + ports: + - 127.0.0.1:5059:5059 + migration-runner: build: ../../etp-core/etp-db environment: diff --git a/e2e-tests/cypress/start-e2e-env.sh b/e2e-tests/cypress/start-e2e-env.sh index 6597600da..df0db7122 100755 --- a/e2e-tests/cypress/start-e2e-env.sh +++ b/e2e-tests/cypress/start-e2e-env.sh @@ -11,5 +11,5 @@ docker compose up --build -d frontend docker compose up --build migration-runner --exit-code-from migration-runner docker compose exec db dropdb -U postgres cypress_test --if-exists --force docker compose exec db createdb -U postgres -T etp_dev cypress_test -echo -e "\e[1;33m Waiting for frontend to be healthy. Can take ~20s. \e[0m" -docker compose up --build --wait frontend --wait backend +echo -e "\e[1;33m Waiting for services to be healthy. Can take ~20s. \e[0m" +docker compose up --build --wait frontend --wait frontend-public --wait backend diff --git a/etp-public/.dockerignore b/etp-public/.dockerignore new file mode 100644 index 000000000..edc3c9251 --- /dev/null +++ b/etp-public/.dockerignore @@ -0,0 +1,15 @@ +# Ignore all files, and then whitelist only required +* + +!package.json +!package-lock.json + +!src/ +!assets/ + +!babel.config.cjs +!jest.config.js +!jest_setup.js +!postcss.config.cjs +!tailwind.config.js +!webpack.config.js diff --git a/etp-public/e2e.Dockerfile b/etp-public/e2e.Dockerfile new file mode 100644 index 000000000..a351e8d0e --- /dev/null +++ b/etp-public/e2e.Dockerfile @@ -0,0 +1,11 @@ +FROM node:20-alpine@sha256:375518d70893d14665b99393079e77bd4947884f123a66ade28744eb8340d229 + +WORKDIR /usr/src/app + +RUN apk --no-cache add curl + +COPY ./package.json package-lock.json ./ +RUN npm ci +COPY ./ ./ + +CMD [ "npm", "run", "dev" ] diff --git a/etp-public/src/components/button.svelte b/etp-public/src/components/button.svelte index 05615f79d..a954a399e 100644 --- a/etp-public/src/components/button.svelte +++ b/etp-public/src/components/button.svelte @@ -15,6 +15,8 @@ export let type = 'submit'; export let disabled = false; + + export let dataCy;