From c090d13df77801cdb89be723c23f5beb15eba1b9 Mon Sep 17 00:00:00 2001 From: Douglas DUTEIL Date: Wed, 30 Oct 2024 08:39:09 +0100 Subject: [PATCH] test(e2e): add seed command --- .github/workflows/end-to-end.yml | 46 +------------------ cypress/e2e/activate_totp/index.cy.ts | 4 ++ .../check_email_deliverability/fixtures.sql | 2 +- .../check_email_deliverability/index.cy.ts | 4 ++ cypress/e2e/delete_account/index.cy.ts | 4 ++ cypress/e2e/delete_totp/index.cy.ts | 4 ++ cypress/e2e/join_and_moderation/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ cypress/e2e/join_must_confirm/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../join_org_with_verified_domain/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../index.cy.ts | 20 ++------ .../index.cy.ts | 4 ++ .../reauthenticate_on_admin_page/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ cypress/e2e/reset_password/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../signin_from_standard_client/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../e2e/signin_with_legacy_scope/index.cy.ts | 4 ++ .../e2e/signin_with_magic_link/index.cy.ts | 4 ++ cypress/e2e/signin_with_right_acr/index.cy.ts | 4 ++ cypress/e2e/signin_with_totp/index.cy.ts | 4 ++ .../index.cy.ts | 4 ++ .../update_personal_information/index.cy.ts | 4 ++ .../e2e/update_totp_application/index.cy.ts | 4 ++ cypress/support/commands.ts | 4 ++ cypress/support/commands/seed.ts | 35 ++++++++++++++ 31 files changed, 149 insertions(+), 62 deletions(-) create mode 100644 cypress/support/commands/seed.ts diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index e84e2bcd5..25e69569c 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -57,52 +57,10 @@ jobs: - update_personal_information - update_totp_application runs-on: ubuntu-22.04 - services: - standard-client: - image: ghcr.io/numerique-gouv/proconnect-test-client - ports: - - 4000:3000 - env: - SITE_TITLE: standard-client - HOST: http://localhost:4000 - PC_CLIENT_ID: standard_client_id - PC_CLIENT_SECRET: standard_client_secret - PC_PROVIDER: ${{ env.MONCOMPTEPRO_HOST }} - PC_SCOPES: openid email profile organization - ACR_VALUE_FOR_2FA: https://proconnect.gouv.fr/assurance/consistency-checked-2fa - STYLESHEET_URL: "" - proconnect-federation-client: - image: ghcr.io/numerique-gouv/proconnect-test-client - ports: - - 4001:3000 - env: - SITE_TITLE: proconnect-federation-client - HOST: http://localhost:4001 - PC_CLIENT_ID: proconnect_federation_client_id - PC_CLIENT_SECRET: proconnect_federation_client_secret - PC_PROVIDER: ${{ env.MONCOMPTEPRO_HOST }} - PC_SCOPES: openid uid given_name usual_name email siren siret organizational_unit belonging_population phone chorusdt is_service_public is_public_service - PC_ID_TOKEN_SIGNED_RESPONSE_ALG: ES256 - PC_USERINFO_SIGNED_RESPONSE_ALG: ES256 - STYLESHEET_URL: "" - LOGIN_HINT: unused1@yopmail.com - ACR_VALUES: eidas1 - redis: - image: redis:7.2 - ports: - - 6379:6379 - postgres: - image: postgres:15.8 - env: - POSTGRES_USER: ${{ env.PGUSER }} - POSTGRES_PASSWORD: ${{ env.PGPASSWORD }} - POSTGRES_DB: ${{ env.PGDATABASE }} - ports: - - 5432:5432 steps: - uses: actions/checkout@v4 - - run: docker compose up --build --detach maildev + - run: docker compose up --build --detach - uses: actions/setup-node@v4 with: @@ -110,8 +68,6 @@ jobs: node-version-file: package.json - run: npm ci --include=dev - run: npm run migrate up - - run: npm run fixtures:load-ci -- cypress/e2e/${{ matrix.e2e_test }}/fixtures.sql - - run: npm run update-organization-info -- 500 - name: Cypress run uses: cypress-io/github-action@v6.7.7 with: diff --git a/cypress/e2e/activate_totp/index.cy.ts b/cypress/e2e/activate_totp/index.cy.ts index 577a42661..ca410d222 100644 --- a/cypress/e2e/activate_totp/index.cy.ts +++ b/cypress/e2e/activate_totp/index.cy.ts @@ -1,6 +1,10 @@ import { generateToken } from "@sunknudsen/totp"; describe("add 2fa authentication", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should add 2fa authentication on account user", function () { cy.visit("/connection-and-account"); diff --git a/cypress/e2e/check_email_deliverability/fixtures.sql b/cypress/e2e/check_email_deliverability/fixtures.sql index b7852c213..7a55b5581 100644 --- a/cypress/e2e/check_email_deliverability/fixtures.sql +++ b/cypress/e2e/check_email_deliverability/fixtures.sql @@ -10,7 +10,7 @@ VALUES 'proconnect_federation_client_secret', ARRAY [ 'http://localhost:4001/login-callback' - ], + ], ARRAY []::varchar[], 'openid uid given_name usual_name email phone siret is_service_public is_public_service', 'http://localhost:4001/', diff --git a/cypress/e2e/check_email_deliverability/index.cy.ts b/cypress/e2e/check_email_deliverability/index.cy.ts index bbae678f8..e33a511eb 100644 --- a/cypress/e2e/check_email_deliverability/index.cy.ts +++ b/cypress/e2e/check_email_deliverability/index.cy.ts @@ -1,4 +1,8 @@ describe("should suggest valid email address", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in", function () { cy.visit("http://localhost:4001"); cy.get("button.proconnect-button").click(); diff --git a/cypress/e2e/delete_account/index.cy.ts b/cypress/e2e/delete_account/index.cy.ts index f0009f8bf..8b338d1fb 100644 --- a/cypress/e2e/delete_account/index.cy.ts +++ b/cypress/e2e/delete_account/index.cy.ts @@ -1,6 +1,10 @@ // describe("delete account", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should delete account", function () { cy.visit("/connection-and-account"); diff --git a/cypress/e2e/delete_totp/index.cy.ts b/cypress/e2e/delete_totp/index.cy.ts index 47d3a6a9a..2a3506582 100644 --- a/cypress/e2e/delete_totp/index.cy.ts +++ b/cypress/e2e/delete_totp/index.cy.ts @@ -1,4 +1,8 @@ describe("delete TOTP connexion", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should delete TOTP application", function () { cy.visit("/connection-and-account"); diff --git a/cypress/e2e/join_and_moderation/index.cy.ts b/cypress/e2e/join_and_moderation/index.cy.ts index a2156a52b..41311dcc8 100644 --- a/cypress/e2e/join_and_moderation/index.cy.ts +++ b/cypress/e2e/join_and_moderation/index.cy.ts @@ -11,6 +11,10 @@ describe("join and moderation", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("will be moderated", function () { cy.visit("/"); diff --git a/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts b/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts index 156380b92..2a78eccee 100644 --- a/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts +++ b/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts @@ -9,6 +9,10 @@ describe("join organizations", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("join collectivité territoriale with official contact domain", function () { cy.visit("/users/join-organization"); cy.login("76450610-4dcc-4664-b9ab-1cea869b62b1@mailslurp.com"); diff --git a/cypress/e2e/join_must_confirm/index.cy.ts b/cypress/e2e/join_must_confirm/index.cy.ts index 316bd0d79..6f73912a8 100644 --- a/cypress/e2e/join_must_confirm/index.cy.ts +++ b/cypress/e2e/join_must_confirm/index.cy.ts @@ -1,6 +1,10 @@ // describe("join organizations", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("join big company with free email provider", function () { cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts b/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts index b00673b92..bd32b3676 100644 --- a/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts +++ b/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts @@ -11,6 +11,10 @@ describe("join organizations", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("join suggested organisation", function () { cy.visit("/"); cy.login("0c5b976c-b6b0-406e-a7ed-08ddae8d2d81@mailslurp.com"); diff --git a/cypress/e2e/join_org_with_verified_domain/index.cy.ts b/cypress/e2e/join_org_with_verified_domain/index.cy.ts index 5155ecfa3..8d46d3402 100644 --- a/cypress/e2e/join_org_with_verified_domain/index.cy.ts +++ b/cypress/e2e/join_org_with_verified_domain/index.cy.ts @@ -13,6 +13,10 @@ describe("join organizations", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("join suggested organisation", function () { cy.visit("/"); cy.login("c6c64542-5601-43e0-b320-b20da72f6edc@mailslurp.com"); diff --git a/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts b/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts index 3f39da3a7..dfa9b9339 100644 --- a/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts +++ b/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts @@ -1,6 +1,10 @@ // describe("join organizations", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("join collectivité territoriale with code send to official contact email", function () { cy.visit("/users/join-organization"); cy.login("c348a2c3-bf54-4f15-bb12-a2d7047c832f@mailslurp.com"); diff --git a/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts b/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts index 199b3e733..8b754b7e7 100644 --- a/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts +++ b/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts @@ -1,6 +1,10 @@ // describe("join organizations", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("join collectivité territoriale with code send to official contact email", function () { cy.visit("/users/join-organization"); cy.login("10efdabd-deb0-4d19-a521-6772ca27acf8@mailslurp.com"); @@ -16,22 +20,6 @@ describe("join organizations", () => { "01714bdb-c5d7-48c9-93ab-73dc78c13609@mailslurp.com", ); - // cy.maildevGetMessageBySubject( - // "[ProConnect] Authentifier un email sur ProConnect", - // ).then((email) => { - // cy.maildevVisitMessageById(email.id); - // cy.get("em:nth-child(1)") - // .invoke("text") - // .then((code) => { - // cy.maildevDeleteMessageById(email.id); - // cy.go("back"); - // cy.get('[name="official_contact_email_verification_token"]').type( - // code, - // ); - // cy.get('[type="submit"]').click(); - // }); - // }); - cy.maildevGetMessageBySubject( "[ProConnect] Authentifier un email sur ProConnect", ) diff --git a/cypress/e2e/join_with_official_contact_email/index.cy.ts b/cypress/e2e/join_with_official_contact_email/index.cy.ts index c1d235948..8bf283fc1 100644 --- a/cypress/e2e/join_with_official_contact_email/index.cy.ts +++ b/cypress/e2e/join_with_official_contact_email/index.cy.ts @@ -1,6 +1,10 @@ // describe("join organizations", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("join collectivité territoriale with official contact email", function () { cy.visit("/users/join-organization"); cy.login("magnus.the.red@prospero.world"); diff --git a/cypress/e2e/reauthenticate_on_admin_page/index.cy.ts b/cypress/e2e/reauthenticate_on_admin_page/index.cy.ts index 8f84fa6b6..5f113b7f6 100644 --- a/cypress/e2e/reauthenticate_on_admin_page/index.cy.ts +++ b/cypress/e2e/reauthenticate_on_admin_page/index.cy.ts @@ -1,4 +1,8 @@ describe("force recent connexion + 2FA on admin pages", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should be redirected after long connexion", function () { cy.visit("/"); diff --git a/cypress/e2e/redirect_after_session_expiration/index.cy.ts b/cypress/e2e/redirect_after_session_expiration/index.cy.ts index d16ba90d7..4da222e0a 100644 --- a/cypress/e2e/redirect_after_session_expiration/index.cy.ts +++ b/cypress/e2e/redirect_after_session_expiration/index.cy.ts @@ -1,4 +1,8 @@ describe("redirect after session expiration", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should be redirected to organization management page", function () { cy.visit("/manage-organizations"); diff --git a/cypress/e2e/reset_password/index.cy.ts b/cypress/e2e/reset_password/index.cy.ts index 540dbc02e..4834ee145 100644 --- a/cypress/e2e/reset_password/index.cy.ts +++ b/cypress/e2e/reset_password/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in with magic link", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should reset password then sign-in", function () { // Visit the signup page cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/set_info_after_account_provisioning/index.cy.ts b/cypress/e2e/set_info_after_account_provisioning/index.cy.ts index 052046f33..94412b4d3 100644 --- a/cypress/e2e/set_info_after_account_provisioning/index.cy.ts +++ b/cypress/e2e/set_info_after_account_provisioning/index.cy.ts @@ -1,6 +1,10 @@ // describe("set info after account provisioning", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should show InclusionConnect welcome page on first visit", function () { // Visit the signup page cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/signin_from_proconnect_federation_client/index.cy.ts b/cypress/e2e/signin_from_proconnect_federation_client/index.cy.ts index ec763b664..50d9030e1 100644 --- a/cypress/e2e/signin_from_proconnect_federation_client/index.cy.ts +++ b/cypress/e2e/signin_from_proconnect_federation_client/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in from proconnect federation client", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in", () => { cy.visit("http://localhost:4001"); cy.get("button.proconnect-button").click(); diff --git a/cypress/e2e/signin_from_standard_client/index.cy.ts b/cypress/e2e/signin_from_standard_client/index.cy.ts index a560906f1..24acda9db 100644 --- a/cypress/e2e/signin_from_standard_client/index.cy.ts +++ b/cypress/e2e/signin_from_standard_client/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in from standard client", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in without org selection when having only one organization", function () { cy.visit("http://localhost:4000"); cy.get("button.proconnect-button").click(); diff --git a/cypress/e2e/signin_with_email_verification/index.cy.ts b/cypress/e2e/signin_with_email_verification/index.cy.ts index b4830443d..6c1ce3586 100644 --- a/cypress/e2e/signin_with_email_verification/index.cy.ts +++ b/cypress/e2e/signin_with_email_verification/index.cy.ts @@ -14,6 +14,10 @@ describe("sign-in with email verification renewal", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in with email verification needed", () => { cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts b/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts index 4e5d82d44..d8b7f93cb 100644 --- a/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts +++ b/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in with email verification renewal", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in with email verification needed", () => { // Visit the signup page cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/signin_with_legacy_scope/index.cy.ts b/cypress/e2e/signin_with_legacy_scope/index.cy.ts index a15e680a7..55bbf9673 100644 --- a/cypress/e2e/signin_with_legacy_scope/index.cy.ts +++ b/cypress/e2e/signin_with_legacy_scope/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in with legacy scope", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in", function () { cy.visit("http://localhost:4000"); cy.setCustomParams({ diff --git a/cypress/e2e/signin_with_magic_link/index.cy.ts b/cypress/e2e/signin_with_magic_link/index.cy.ts index 8dec9dd75..f31664f48 100644 --- a/cypress/e2e/signin_with_magic_link/index.cy.ts +++ b/cypress/e2e/signin_with_magic_link/index.cy.ts @@ -1,6 +1,10 @@ // describe("sign-in with magic link", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-up with magic link", function () { cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/signin_with_right_acr/index.cy.ts b/cypress/e2e/signin_with_right_acr/index.cy.ts index 25bb71b75..ef6eb3aff 100644 --- a/cypress/e2e/signin_with_right_acr/index.cy.ts +++ b/cypress/e2e/signin_with_right_acr/index.cy.ts @@ -4,6 +4,10 @@ describe("sign-in with a client not requiring any acr", () => { cy.setRequestedAcrs(); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in an return the right acr value", function () { cy.get("button#custom-connection").click({ force: true }); diff --git a/cypress/e2e/signin_with_totp/index.cy.ts b/cypress/e2e/signin_with_totp/index.cy.ts index b3ab324f3..e970fa484 100644 --- a/cypress/e2e/signin_with_totp/index.cy.ts +++ b/cypress/e2e/signin_with_totp/index.cy.ts @@ -1,4 +1,8 @@ describe("sign-in with TOTP on untrusted browser", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should sign-in with password and TOTP", function () { cy.visit("http://localhost:4000"); cy.get("button.proconnect-button").click(); diff --git a/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts b/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts index 5148767fa..add0de7ea 100644 --- a/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts +++ b/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts @@ -9,6 +9,10 @@ describe("Signup into new entreprise unipersonnelle", () => { ); }); + it("should seed the database once", function () { + cy.seed(); + }); + it("creates a user", function () { // Visit the signup page cy.visit("/users/start-sign-in"); diff --git a/cypress/e2e/update_personal_information/index.cy.ts b/cypress/e2e/update_personal_information/index.cy.ts index 7a0bac763..6828724da 100644 --- a/cypress/e2e/update_personal_information/index.cy.ts +++ b/cypress/e2e/update_personal_information/index.cy.ts @@ -1,4 +1,8 @@ describe("Signup into new entreprise unipersonnelle", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("Should send email when user updates personal information", function () { cy.visit("/personal-information"); diff --git a/cypress/e2e/update_totp_application/index.cy.ts b/cypress/e2e/update_totp_application/index.cy.ts index 44fd09087..c5a9baaeb 100644 --- a/cypress/e2e/update_totp_application/index.cy.ts +++ b/cypress/e2e/update_totp_application/index.cy.ts @@ -1,6 +1,10 @@ import { generateToken } from "@sunknudsen/totp"; describe("update TOTP application", () => { + it("should seed the database once", function () { + cy.seed(); + }); + it("should update TOTP application, and replace old app with new", function () { cy.visit("/connection-and-account"); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 8473bcd5a..1be30c222 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -2,6 +2,7 @@ import { generateToken } from "@sunknudsen/totp"; import { checkA11y } from "./a11y/checkA11y"; +import { seed } from "./commands/seed"; // @@ -18,6 +19,7 @@ declare global { mfaLogin(email: string): Chainable; setCustomParams(customParams: any): Chainable; setRequestedAcrs(requestedAcrs?: string[]): Chainable; + seed: typeof seed; } } } @@ -97,3 +99,5 @@ Cypress.Commands.add("setRequestedAcrs", (requestedAcrs) => { cy.setCustomParams(customParams); }); + +Cypress.Commands.add("seed", seed); diff --git a/cypress/support/commands/seed.ts b/cypress/support/commands/seed.ts new file mode 100644 index 000000000..de348c23f --- /dev/null +++ b/cypress/support/commands/seed.ts @@ -0,0 +1,35 @@ +// + +import { dirname } from "path"; + +// + +export function seed() { + { + const command = "npm run delete-database"; + cy.task("log", `$ ${command}`); + cy.exec(command, { env: { ENABLE_DATABASE_DELETION: "True" } }).then( + (result) => cy.task("log", result.stdout), + ); + } + { + const command = "npm run migrate up"; + cy.task("log", `$ ${command}`); + cy.exec(command).then((result) => cy.task("log", result.stdout)); + } + { + const scope = dirname(Cypress.spec.relative); + const command = `npm run fixtures:load-ci -- ${scope}/fixtures.sql`; + cy.task("log", `$ ${command}`); + cy.exec(command).then((result) => cy.task("log", result.stdout)); + } + { + const command = "npm run update-organization-info -- 2000"; + cy.task("log", `$ ${command}`); + cy.exec(command, { timeout: 10_000 }).then((result) => + cy.task("log", result.stdout), + ); + } + + return cy.wrap(undefined); +}