Skip to content

Commit 3ee71db

Browse files
committed
✅ add test for feature armee suggestion
1 parent 655df39 commit 3ee71db

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

cypress/e2e/signup_with_suggestion/env.conf

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
INSERT INTO
2+
organizations (id, siret, created_at, updated_at)
3+
VALUES
4+
(
5+
1,
6+
'11009001600053',
7+
CURRENT_TIMESTAMP,
8+
CURRENT_TIMESTAMP
9+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
3+
describe("sign-up with suggestion", () => {
4+
it("should seed the database once", function () {
5+
cy.seed();
6+
});
7+
8+
it("should sign-up with magic link and be suggested the Ministere des armees organization", function () {
9+
// Visit the signup page
10+
cy.visit("/users/start-sign-in");
11+
12+
cy.get('[name="login"]').type("user@intradef.gouv.fr");
13+
cy.get('[type="submit"]').click();
14+
15+
cy.get('[name="password"]').type(
16+
"This super secret password is hidden well!",
17+
);
18+
cy.get('[action="/users/sign-up"] [type="submit"]').click();
19+
20+
// Check that the website is waiting for the user to verify their email
21+
cy.get("#verify-email > div > p").contains("user@intradef.gouv.fr");
22+
23+
cy.verifyEmail();
24+
25+
// Fill the user's personal information
26+
cy.get('[name="given_name"]').type("Loïs");
27+
cy.get('[name="family_name"]').type("Lane");
28+
cy.get('[type="submit"]').click();
29+
30+
// Check that the ministere des armees is preselected
31+
cy.url().should("include", "users/organization-suggestions");
32+
cy.get("#submit-join-organization-1").contains("Ministere des armees");
33+
});
34+
});

src/managers/organization/join.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ import {
5050
findRejectedModeration,
5151
} from "../../repositories/moderation";
5252
import {
53+
findBySiret,
5354
findByUserId,
5455
findByVerifiedEmailDomain,
5556
getById,
56-
getBySiret,
5757
} from "../../repositories/organization/getters";
5858
import {
5959
linkUserToOrganization,
@@ -113,7 +113,7 @@ export const getOrganizationSuggestions = async ({
113113
}
114114

115115
if (isArmeeDomain(domain)) {
116-
const armeeOrganization = await getBySiret("11009001600053");
116+
const armeeOrganization = await findBySiret("11009001600053");
117117
if (armeeOrganization) {
118118
return [armeeOrganization];
119119
}

src/repositories/organization/getters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const findByUserId = findByUserIdFactory({
1717
pg: getDatabaseConnection(),
1818
});
1919

20-
export const getBySiret = async (siret: string) => {
20+
export const findBySiret = async (siret: string) => {
2121
const connection = getDatabaseConnection();
2222

2323
const { rows }: QueryResult<Organization> = await connection.query(
2424
`
25-
SELECT id, siret
25+
SELECT *
2626
FROM organizations
2727
WHERE siret = $1
2828
`,

0 commit comments

Comments
 (0)