Skip to content

Commit

Permalink
test(e2e): add seed command
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Nov 13, 2024
1 parent ec921eb commit b152dc5
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,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/[email protected]
with:
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/activate_totp/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/check_email_deliverability/fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/check_email_deliverability/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/delete_account/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/delete_totp/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/join_and_moderation/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe("join and moderation", () => {
);
});

it("should seed the database once", function () {
cy.seed();
});

it("will be moderated", function () {
cy.visit("/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/join_must_confirm/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/join_org_with_verified_domain/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
Expand Down
Original file line number Diff line number Diff line change
@@ -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("[email protected]");
Expand Down
Original file line number Diff line number Diff line change
@@ -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("[email protected]");
Expand All @@ -16,22 +20,6 @@ describe("join organizations", () => {
"[email protected]",
);

// 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",
)
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/join_with_official_contact_email/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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("[email protected]");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/reauthenticate_on_admin_page/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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("/");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/redirect_after_session_expiration/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/reset_password/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/set_info_after_account_provisioning/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_from_standard_client/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_with_email_verification/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_with_legacy_scope/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_with_magic_link/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_with_right_acr/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signin_with_totp/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/update_personal_information/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/update_totp_application/index.cy.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
4 changes: 4 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { generateToken } from "@sunknudsen/totp";
import { checkA11y } from "./a11y/checkA11y";
import { seed } from "./commands/seed";

//

Expand All @@ -18,6 +19,7 @@ declare global {
mfaLogin(email: string): Chainable<void>;
setCustomParams(customParams: any): Chainable<void>;
setRequestedAcrs(requestedAcrs?: string[]): Chainable<void>;
seed: typeof seed;
}
}
}
Expand Down Expand Up @@ -97,3 +99,5 @@ Cypress.Commands.add("setRequestedAcrs", (requestedAcrs) => {

cy.setCustomParams(customParams);
});

Cypress.Commands.add("seed", seed);
35 changes: 35 additions & 0 deletions cypress/support/commands/seed.ts
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b152dc5

Please sign in to comment.