Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cypress/e2e/join_and_moderation/fixtures.sql
Original file line number Diff line number Diff line change
@@ -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);
23 changes: 21 additions & 2 deletions cypress/e2e/join_and_moderation/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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éé !");
});
});
3 changes: 3 additions & 0 deletions src/managers/organization/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addDomain,
deleteEmailDomainsByVerificationTypes,
} from "../../repositories/email-domain";
import { deletePendingModeration } from "../../repositories/moderation";
import {
findByUserId,
findById as findOrganizationById,
Expand Down Expand Up @@ -47,6 +48,8 @@ export const quitOrganization = async ({
throw new NotFoundError();
}

await deletePendingModeration({ user_id, organization_id });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: add this treatment in https://github.com/proconnect-gouv/hyyypertool : put this function in deleteUserOrganization, share this function with hyyypertool via npm


return true;
};

Expand Down
24 changes: 24 additions & 0 deletions src/repositories/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Moderation> = 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();
};