diff --git a/cypress/e2e/join_and_moderation/fixtures.sql b/cypress/e2e/join_and_moderation/fixtures.sql index b188fe51a..ae30a2560 100644 --- a/cypress/e2e/join_and_moderation/fixtures.sql +++ b/cypress/e2e/join_and_moderation/fixtures.sql @@ -1,10 +1,15 @@ INSERT INTO users - (id, email, email_verified, email_verified_at, encrypted_password, created_at, updated_at, given_name, family_name, - phone_number, job) + (id, email, email_verified, email_verified_at, encrypted_password, created_at, updated_at, given_name, family_name, job) VALUES - (1, 'lion.eljonson@darkangels.world', true, CURRENT_TIMESTAMP, '$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Jean', 'Nouveau', '0123456789', 'Sbire'); + (1, 'god-emperor@mankind.world', true, CURRENT_TIMESTAMP, '$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'God', 'Emperor', 'God Emperor'), + (2, 'lion.eljonson@darkangels.world', true, CURRENT_TIMESTAMP, '$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Lion', 'El''Jonson', 'Primarque'); INSERT INTO organizations (id, siret, created_at, updated_at) VALUES (1, '66204244933106', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + +INSERT INTO email_domains + (id, organization_id, domain, verification_type, verified_at) +VALUES + (1, 1, 'mankind.world', null, CURRENT_TIMESTAMP); diff --git a/cypress/e2e/join_and_moderation/index.cy.ts b/cypress/e2e/join_and_moderation/index.cy.ts index 84f2cec19..18345ea04 100644 --- a/cypress/e2e/join_and_moderation/index.cy.ts +++ b/cypress/e2e/join_and_moderation/index.cy.ts @@ -8,14 +8,33 @@ describe("join and moderation", () => { it("will be moderated", function () { cy.visit("/"); + cy.title().should("include", "S'inscrire ou se connecter -"); cy.login("lion.eljonson@darkangels.world"); - cy.get('[name="siret"]').type("66204244933106"); - cy.get('[type="submit"]').click(); + cy.title().should("include", "Rejoindre une organisation -"); + cy.contains("SIRET de l’organisation que vous représentez").click(); + cy.focused().clear().type("66204244933106"); + cy.contains("Enregistrer").click(); + cy.title().should("include", "Rattachement en cours -"); cy.contains("Demande en cours"); cy.contains( "Nous vérifions votre lien à l’organisation, vous recevrez un email de confirmation dès que votre compte sera validé.", ); }); + + it("will join with a non blocking moderation", function () { + cy.visit("/"); + + cy.title().should("include", "S'inscrire ou se connecter -"); + cy.login("god-emperor@mankind.world"); + + cy.title().should("include", "Rejoindre une organisation -"); + cy.contains("SIRET de l’organisation que vous représentez").click(); + cy.focused().clear().type("66204244933106"); + cy.contains("Enregistrer").click(); + + cy.title().should("include", "Compte créé -"); + cy.contains("Votre compte est créé !"); + }); }); diff --git a/src/managers/organization/main.ts b/src/managers/organization/main.ts index bbd23c90a..0ddb47feb 100644 --- a/src/managers/organization/main.ts +++ b/src/managers/organization/main.ts @@ -6,6 +6,7 @@ import { addDomain, deleteEmailDomainsByVerificationTypes, } from "../../repositories/email-domain"; +import { deletePendingModeration } from "../../repositories/moderation"; import { findByUserId, findById as findOrganizationById, @@ -47,6 +48,8 @@ export const quitOrganization = async ({ throw new NotFoundError(); } + await deletePendingModeration({ user_id, organization_id }); + return true; }; diff --git a/src/repositories/moderation.ts b/src/repositories/moderation.ts index 4a2ff5823..9ab3997f9 100644 --- a/src/repositories/moderation.ts +++ b/src/repositories/moderation.ts @@ -76,3 +76,27 @@ export const deleteModeration = async (id: number) => { return rowCount > 0; }; + +export const deletePendingModeration = async ({ + user_id, + organization_id, +}: { + user_id: number; + organization_id: number; +}) => { + const connection = getDatabaseConnection(); + + const { rows }: QueryResult = await connection.query( + ` +DELETE FROM + moderations +WHERE + user_id = $1 + AND organization_id = $2 + AND moderated_at IS NULL; +`, + [user_id, organization_id], + ); + + return rows.shift(); +};