Skip to content

Commit

Permalink
AE-2316: Add e2e test for public site to check the visibility of expi…
Browse files Browse the repository at this point in the history
…red energiatodistukset

There might be some problem with the e2e configuration as the sites
layout is somehow broken in the cypress tests but it might also be due
to running the tests with Electron (only thing I can use with WSL). This
is sufficient to test the functionality of the site though.
  • Loading branch information
solita-juhohaa committed Oct 29, 2024
1 parent 0f7ab3a commit e89b546
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e-tests/cypress/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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');
});
});
});
18 changes: 18 additions & 0 deletions e2e-tests/cypress/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/cypress/start-e2e-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions etp-public/.dockerignore
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions etp-public/e2e.Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
3 changes: 3 additions & 0 deletions etp-public/src/components/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
export let type = 'submit';
export let disabled = false;
export let dataCy;
</script>

<style>
Expand Down Expand Up @@ -56,6 +58,7 @@
on:click
{disabled}
{type}
data-cy={dataCy}
class:bg-lightgrey={disabled}
class:cursor-not-allowed={disabled}
class:shadow-none={disabled}
Expand Down
2 changes: 1 addition & 1 deletion etp-public/src/components/table-ethaku.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<tbody>
{#each eTodistukset as todistus}
<tr>
<td>
<td data-cy="ethaku-tunnus">
<a
class="block"
href={`/energiatodistus?id=${todistus.id}&versio=${todistus.versio}${ref}`}
Expand Down
2 changes: 1 addition & 1 deletion etp-public/src/pages/ethaku.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
{/if}
<div class="w-full md:w-11/12 mt-4 flex flex-col sm:flex-row">
<Button {...buttonStyles.green} disabled={!isValid} type="submit">
<Button {...buttonStyles.green} disabled={!isValid} type="submit" dataCy="ethaku-hae">
{$_('HAE')}
</Button>
<Button {...buttonStyles.ashblue} type="reset">
Expand Down

0 comments on commit e89b546

Please sign in to comment.