@proconnect-gouv/proconnect.identite 11.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/connectors/index.d.ts +0 -37
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +2 -4
  5. package/dist/managers/certification/process-certification-dirigeant.d.ts +28 -1
  6. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  7. package/dist/managers/certification/process-certification-dirigeant.js +17 -5
  8. package/dist/managers/organization/get-organization-info.d.ts +21 -1
  9. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  10. package/dist/managers/organization/get-organization-info.js +44 -41
  11. package/dist/managers/organization/index.d.ts +0 -1
  12. package/dist/managers/organization/index.d.ts.map +1 -1
  13. package/dist/managers/organization/index.js +0 -1
  14. package/dist/repositories/email-domain/index.d.ts +0 -3
  15. package/dist/repositories/email-domain/index.d.ts.map +1 -1
  16. package/dist/repositories/email-domain/index.js +0 -1
  17. package/dist/repositories/organization/index.d.ts +0 -1
  18. package/dist/repositories/organization/index.d.ts.map +1 -1
  19. package/dist/repositories/organization/index.js +0 -1
  20. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +9 -0
  21. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +1 -0
  22. package/dist/services/organization/get-member-ids-promoted-by-domain.js +11 -0
  23. package/dist/services/organization/index.d.ts +1 -0
  24. package/dist/services/organization/index.d.ts.map +1 -1
  25. package/dist/services/organization/index.js +1 -0
  26. package/package.json +1 -1
  27. package/src/connectors/index.ts +0 -5
  28. package/src/managers/certification/process-certification-dirigeant.test.ts +12 -1
  29. package/src/managers/certification/process-certification-dirigeant.ts +23 -4
  30. package/src/managers/organization/get-organization-info.test.ts +75 -4
  31. package/src/managers/organization/get-organization-info.test.ts.snapshot +104 -80
  32. package/src/managers/organization/get-organization-info.ts +63 -56
  33. package/src/managers/organization/index.ts +0 -1
  34. package/src/repositories/email-domain/index.ts +0 -3
  35. package/src/repositories/organization/index.ts +0 -1
  36. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +100 -0
  37. package/src/services/organization/get-member-ids-promoted-by-domain.ts +27 -0
  38. package/src/services/organization/index.ts +1 -0
  39. package/dist/managers/organization/mark-domain-as-verified.d.ts +0 -18
  40. package/dist/managers/organization/mark-domain-as-verified.d.ts.map +0 -1
  41. package/dist/managers/organization/mark-domain-as-verified.js +0 -64
  42. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +0 -3
  43. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +0 -1
  44. package/dist/managers/user/assign-user-verification-type-to-domain.js +0 -20
  45. package/dist/managers/user/index.d.ts +0 -2
  46. package/dist/managers/user/index.d.ts.map +0 -1
  47. package/dist/managers/user/index.js +0 -1
  48. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts +0 -8
  49. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts.map +0 -1
  50. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.js +0 -19
  51. package/dist/repositories/organization/find-users-by-organization.d.ts +0 -34
  52. package/dist/repositories/organization/find-users-by-organization.d.ts.map +0 -1
  53. package/dist/repositories/organization/find-users-by-organization.js +0 -16
  54. package/src/managers/organization/mark-domain-as-verified.test.ts +0 -250
  55. package/src/managers/organization/mark-domain-as-verified.ts +0 -123
  56. package/src/managers/user/assign-user-verification-type-to-domain.test.ts +0 -105
  57. package/src/managers/user/assign-user-verification-type-to-domain.ts +0 -40
  58. package/src/managers/user/index.ts +0 -1
  59. package/src/repositories/email-domain/delete-email-domains-by-verification-types.test.ts +0 -49
  60. package/src/repositories/email-domain/delete-email-domains-by-verification-types.ts +0 -45
  61. package/src/repositories/organization/find-users-by-organization.test.ts +0 -51
  62. package/src/repositories/organization/find-users-by-organization.test.ts.snapshot +0 -35
  63. package/src/repositories/organization/find-users-by-organization.ts +0 -30
@@ -0,0 +1,100 @@
1
+ //
2
+
3
+ import { getMemberIdsPromotedByDomain } from "#src/services/organization";
4
+ import assert from "node:assert/strict";
5
+ import { describe, it } from "node:test";
6
+
7
+ //
8
+
9
+ describe("getMemberIdsPromotedByDomain", () => {
10
+ it("should promote unverified and super weak members of the domain", () => {
11
+ assert.deepEqual(
12
+ getMemberIdsPromotedByDomain({
13
+ domain: "darkangels.world",
14
+ members: [
15
+ {
16
+ email: "lion.eljonson@darkangels.world",
17
+ id: 1,
18
+ verification_type: "no_validation_means_available",
19
+ },
20
+ {
21
+ email: "cat.eljonson@darkangels.world",
22
+ id: 2,
23
+ verification_type:
24
+ "no_verification_means_for_entreprise_unipersonnelle",
25
+ },
26
+ {
27
+ email: "tiger.eljonson@darkangels.world",
28
+ id: 3,
29
+ verification_type: "no_verification_means_for_small_association",
30
+ },
31
+ {
32
+ email: "wolf.eljonson@darkangels.world",
33
+ id: 4,
34
+ verification_type: "no_verification_means_for_small_organization",
35
+ },
36
+ {
37
+ email: "mouse.eljonson@darkangels.world",
38
+ id: 5,
39
+ verification_type: "domain_not_verified_yet",
40
+ },
41
+ ],
42
+ }),
43
+ [1, 2, 3, 4, 5],
44
+ );
45
+ });
46
+
47
+ it("should not promote members of another domain", () => {
48
+ assert.deepEqual(
49
+ getMemberIdsPromotedByDomain({
50
+ domain: "darkangels.world",
51
+ members: [
52
+ {
53
+ email: "foo@bar.world",
54
+ id: 1,
55
+ verification_type: "no_validation_means_available",
56
+ },
57
+ {
58
+ email: "luther@sub.darkangels.world",
59
+ id: 2,
60
+ verification_type: "no_validation_means_available",
61
+ },
62
+ ],
63
+ }),
64
+ [],
65
+ );
66
+ });
67
+
68
+ it("should not promote members with a verified link", () => {
69
+ assert.deepEqual(
70
+ getMemberIdsPromotedByDomain({
71
+ domain: "darkangels.world",
72
+ members: [
73
+ {
74
+ email: "lion.eljonson@darkangels.world",
75
+ id: 1,
76
+ verification_type: "organization_dirigeant",
77
+ },
78
+ {
79
+ email: "azrael@darkangels.world",
80
+ id: 2,
81
+ verification_type: "domain",
82
+ },
83
+ {
84
+ email: "belial@darkangels.world",
85
+ id: 3,
86
+ verification_type: "official_contact_email",
87
+ },
88
+ ],
89
+ }),
90
+ [],
91
+ );
92
+ });
93
+
94
+ it("should not promote anyone without members", () => {
95
+ assert.deepEqual(
96
+ getMemberIdsPromotedByDomain({ domain: "darkangels.world", members: [] }),
97
+ [],
98
+ );
99
+ });
100
+ });
@@ -0,0 +1,27 @@
1
+ //
2
+
3
+ import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
4
+ import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
5
+
6
+ //
7
+
8
+ export function getMemberIdsPromotedByDomain({
9
+ domain,
10
+ members,
11
+ }: {
12
+ domain: string;
13
+ members: ReadonlyArray<{
14
+ email: string;
15
+ id: number;
16
+ verification_type: string;
17
+ }>;
18
+ }) {
19
+ return members
20
+ .filter(
21
+ ({ email, verification_type }) =>
22
+ getEmailDomain(email) === domain &&
23
+ (UnverifiedLinkEnum.safeParse(verification_type).success ||
24
+ SuperWeakLinkEnum.safeParse(verification_type).success),
25
+ )
26
+ .map(({ id }) => id);
27
+ }
@@ -1,6 +1,7 @@
1
1
  //
2
2
 
3
3
  export * from "./compute-service-public-info.js";
4
+ export * from "./get-member-ids-promoted-by-domain.js";
4
5
  export * from "./is-domain-allowed-for-organization.js";
5
6
  export * from "./is-entreprise-unipersonnelle.js";
6
7
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -1,18 +0,0 @@
1
- import type { Context } from "#src/connectors";
2
- import { type EmailDomainNoPendingVerificationType } from "#src/types";
3
- export declare function markDomainAsVerifiedFactory(context: Context): ({ organization_id, domain, domain_verification_type, }: {
4
- organization_id: number;
5
- domain: string;
6
- domain_verification_type: EmailDomainNoPendingVerificationType;
7
- }) => Promise<{
8
- id: number;
9
- organization_id: number;
10
- domain: string;
11
- verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
12
- can_be_suggested: boolean;
13
- verified_at: Date | null;
14
- created_at: Date;
15
- updated_at: Date;
16
- }>;
17
- export type MarkDomainAsVerifiedHandler = ReturnType<typeof markDomainAsVerifiedFactory>;
18
- //# sourceMappingURL=mark-domain-as-verified.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAkFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
@@ -1,64 +0,0 @@
1
- //
2
- import { NotFoundError } from "#src/errors";
3
- import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
4
- import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, } from "#src/types";
5
- import { isEmpty } from "lodash-es";
6
- import { match } from "ts-pattern";
7
- //
8
- export function markDomainAsVerifiedFactory(context) {
9
- const assignUserVerificationTypeToDomain = assignUserVerificationTypeToDomainFactory(context);
10
- const { repository: { email_domains, organizations }, } = context;
11
- return async function markDomainAsVerified({ organization_id, domain, domain_verification_type, }) {
12
- const organization = await organizations.findById(organization_id);
13
- if (isEmpty(organization)) {
14
- throw new NotFoundError();
15
- }
16
- return match(domain_verification_type)
17
- .with(...EmailDomainApprovedVerificationValues, async (approved_verification_type) => {
18
- await assignUserVerificationTypeToDomain(organization_id, domain);
19
- return markDomainAsApproved({
20
- organization_id,
21
- domain,
22
- domain_verification_type: approved_verification_type,
23
- });
24
- })
25
- .with(...EmailDomainRejectedVerificationValues, (rejected_verification_type) => markDomainAsRejected({
26
- organization_id,
27
- domain,
28
- domain_verification_type: rejected_verification_type,
29
- }))
30
- .exhaustive();
31
- };
32
- async function markDomainAsApproved({ organization_id, domain, domain_verification_type, }) {
33
- await email_domains.deleteEmailDomainsByVerificationTypes({
34
- organization_id,
35
- domain,
36
- domain_verification_types: [
37
- ...EmailDomainApprovedVerificationValues,
38
- ...EmailDomainPendingVerificationValues,
39
- ...EmailDomainRejectedVerificationValues,
40
- ],
41
- });
42
- return email_domains.addDomain({
43
- organization_id,
44
- domain,
45
- verification_type: domain_verification_type,
46
- });
47
- }
48
- async function markDomainAsRejected({ organization_id, domain, domain_verification_type, }) {
49
- await email_domains.deleteEmailDomainsByVerificationTypes({
50
- organization_id,
51
- domain,
52
- domain_verification_types: [
53
- ...EmailDomainApprovedVerificationValues,
54
- ...EmailDomainPendingVerificationValues,
55
- ...EmailDomainRejectedVerificationValues,
56
- ],
57
- });
58
- return email_domains.addDomain({
59
- organization_id,
60
- domain,
61
- verification_type: domain_verification_type,
62
- });
63
- }
64
- }
@@ -1,3 +0,0 @@
1
- import type { Context } from "#src/connectors";
2
- export declare function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }: Context): (organization_id: number, domain: string) => Promise<void>;
3
- //# sourceMappingURL=assign-user-verification-type-to-domain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM/C,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,GACnD,EAAE,OAAO,IAEN,iBAAiB,MAAM,EACvB,QAAQ,MAAM,mBA0BjB"}
@@ -1,20 +0,0 @@
1
- //
2
- import { LinkEnum, SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
3
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
4
- //
5
- export function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }) {
6
- return async function assignUserVerificationTypeToDomain(organization_id, domain) {
7
- const usersInOrganization = await organizations.findUsers(organization_id);
8
- await Promise.all(usersInOrganization.map(({ id: user_id, email, verification_type: link_verification_type }) => {
9
- const userDomain = getEmailDomain(email);
10
- if (userDomain === domain &&
11
- (UnverifiedLinkEnum.safeParse(link_verification_type).success ||
12
- SuperWeakLinkEnum.safeParse(link_verification_type).success)) {
13
- return users_organizations.update({ organization_id, user_id }, {
14
- verification_type: LinkEnum.enum.domain,
15
- });
16
- }
17
- return null;
18
- }));
19
- };
20
- }
@@ -1,2 +0,0 @@
1
- export * from "./assign-user-verification-type-to-domain.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/managers/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./assign-user-verification-type-to-domain.js";
@@ -1,8 +0,0 @@
1
- import type { DatabaseContext, EmailDomain, EmailDomainVerificationType } from "#src/types";
2
- export declare function deleteEmailDomainsByVerificationTypesFactory({ pg, }: DatabaseContext): ({ organization_id, domain, domain_verification_types, }: {
3
- organization_id: EmailDomain["organization_id"];
4
- domain_verification_types: EmailDomainVerificationType[];
5
- domain: EmailDomain["domain"];
6
- }) => Promise<import("pg").QueryResult<any>>;
7
- export type DeleteEmailDomainsByVerificationTypesHandler = ReturnType<typeof deleteEmailDomainsByVerificationTypesFactory>;
8
- //# sourceMappingURL=delete-email-domains-by-verification-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"delete-email-domains-by-verification-types.d.ts","sourceRoot":"","sources":["../../../src/repositories/email-domain/delete-email-domains-by-verification-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AAIpB,wBAAgB,4CAA4C,CAAC,EAC3D,EAAE,GACH,EAAE,eAAe,IAC4C,yDAIzD;IACD,eAAe,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAChD,yBAAyB,EAAE,2BAA2B,EAAE,CAAC;IACzD,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAC/B,4CAmBF;AAED,MAAM,MAAM,4CAA4C,GAAG,UAAU,CACnE,OAAO,4CAA4C,CACpD,CAAC"}
@@ -1,19 +0,0 @@
1
- //
2
- //
3
- export function deleteEmailDomainsByVerificationTypesFactory({ pg, }) {
4
- return async function deleteEmailDomainsByVerificationTypes({ organization_id, domain, domain_verification_types, }) {
5
- const SQL_VERIFICATION_TYPES = domain_verification_types
6
- .map((type) => `verification_type = '${type}'`)
7
- .join(" OR ");
8
- return pg.query(`
9
- DELETE FROM email_domains
10
- WHERE
11
- ${[
12
- "organization_id = $1",
13
- "domain = $2",
14
- `(${SQL_VERIFICATION_TYPES})`,
15
- ].join(" AND ")}
16
- ;
17
- `, [organization_id, domain]);
18
- };
19
- }
@@ -1,34 +0,0 @@
1
- import type { DatabaseContext } from "#src/types";
2
- export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number) => Promise<({
3
- created_at: Date;
4
- current_challenge: string | null;
5
- email: string;
6
- email_verified: boolean;
7
- email_verified_at: Date | null;
8
- encrypted_password: string | null;
9
- encrypted_totp_key: string | null;
10
- family_name: string | null;
11
- force_2fa: boolean;
12
- given_name: string | null;
13
- id: number;
14
- job: string | null;
15
- last_sign_in_at: Date | null;
16
- magic_link_sent_at: Date | null;
17
- magic_link_token: string | null;
18
- needs_inclusionconnect_onboarding_help: boolean;
19
- needs_inclusionconnect_welcome_page: boolean;
20
- phone_number: string | null;
21
- reset_password_sent_at: Date | null;
22
- reset_password_token: string | null;
23
- sign_in_count: number;
24
- totp_key_verified_at: Date | null;
25
- updated_at: Date;
26
- verify_email_sent_at: Date | null;
27
- verify_email_token: string | null;
28
- } & {
29
- is_external: boolean;
30
- verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association" | "no_verification_means_for_small_organization";
31
- verified_at: Date | null;
32
- has_been_greeted: boolean;
33
- })[]>;
34
- //# sourceMappingURL=find-users-by-organization.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,iBAAiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiBtE"}
@@ -1,16 +0,0 @@
1
- //
2
- //
3
- export function findUsersByOrganizationFactory({ pg }) {
4
- return async function findUsersByOrganization(organization_id) {
5
- const { rows } = await pg.query(`
6
- SELECT u.*,
7
- uo.is_external,
8
- uo.verification_type,
9
- uo.verified_at,
10
- uo.has_been_greeted
11
- FROM users u
12
- INNER JOIN users_organizations AS uo ON uo.user_id = u.id
13
- WHERE uo.organization_id = $1`, [organization_id]);
14
- return rows;
15
- };
16
- }
@@ -1,250 +0,0 @@
1
- //
2
-
3
- import { NotFoundError } from "#src/errors";
4
- import { context, emptyDatabase, migrate, pg } from "#testing";
5
- import assert from "node:assert/strict";
6
- import { before, beforeEach, describe, it } from "node:test";
7
- import { markDomainAsVerifiedFactory } from "./mark-domain-as-verified.js";
8
-
9
- //
10
-
11
- const markDomainAsVerified = markDomainAsVerifiedFactory(context);
12
-
13
- describe("markDomainAsVerified", () => {
14
- before(migrate);
15
- beforeEach(emptyDatabase);
16
-
17
- it("should update organization members", async () => {
18
- await pg.sql`
19
- INSERT INTO organizations
20
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
21
- VALUES
22
- (1, 'Dark Angels', 'Dark Angels Legion', '🦁', '4444-04-04', '4444-04-04')
23
- ;
24
- `;
25
- await pg.sql`
26
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
27
- VALUES (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
28
- `;
29
- await pg.sql`
30
- INSERT INTO users_organizations
31
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
32
- VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle')
33
- ;
34
- `;
35
- await pg.sql`
36
- INSERT INTO email_domains (organization_id, domain, verification_type)
37
- VALUES (1, 'darkangels.world', 'not_verified_yet')
38
- `;
39
-
40
- await markDomainAsVerified({
41
- domain: "darkangels.world",
42
- domain_verification_type: "verified",
43
- organization_id: 1,
44
- });
45
-
46
- // user verification_type should be updated to "domain"
47
- const { rows: userLinks } = await pg.sql`
48
- SELECT user_id, verification_type
49
- FROM users_organizations
50
- WHERE organization_id = 1
51
- `;
52
- assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
53
-
54
- // old email_domain records should be replaced with "verified"
55
- const { rows: emailDomains } = await pg.sql`
56
- SELECT domain, verification_type
57
- FROM email_domains
58
- WHERE organization_id = 1
59
- ORDER BY verification_type
60
- `;
61
- assert.deepEqual(emailDomains, [
62
- { domain: "darkangels.world", verification_type: "verified" },
63
- ]);
64
- });
65
-
66
- it("approving a domain should replace an existing rejection for the same domain", async () => {
67
- await pg.sql`
68
- INSERT INTO organizations
69
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
70
- VALUES
71
- (1, 'Night Lords', 'Night Lords Legion', '🦇', '4444-04-04', '4444-04-04')
72
- ;
73
- `;
74
- await pg.sql`
75
- INSERT INTO email_domains (organization_id, domain, verification_type)
76
- VALUES (1, 'nightlords.world', 'refused')
77
- `;
78
-
79
- await markDomainAsVerified({
80
- domain: "nightlords.world",
81
- domain_verification_type: "verified",
82
- organization_id: 1,
83
- });
84
-
85
- const { rows: emailDomains } = await pg.sql`
86
- SELECT domain, verification_type
87
- FROM email_domains
88
- WHERE organization_id = 1
89
- ORDER BY verification_type
90
- `;
91
- assert.deepEqual(emailDomains, [
92
- { domain: "nightlords.world", verification_type: "verified" },
93
- ]);
94
- });
95
-
96
- it("rejecting a domain should replace an existing approval for the same domain", async () => {
97
- await pg.sql`
98
- INSERT INTO organizations
99
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
100
- VALUES
101
- (1, 'Thousand Sons', 'Thousand Sons Legion', '📖', '4444-04-04', '4444-04-04')
102
- ;
103
- `;
104
- await pg.sql`
105
- INSERT INTO email_domains (organization_id, domain, verification_type)
106
- VALUES (1, 'thousandsons.world', 'verified')
107
- `;
108
-
109
- await markDomainAsVerified({
110
- domain: "thousandsons.world",
111
- domain_verification_type: "refused",
112
- organization_id: 1,
113
- });
114
-
115
- const { rows: emailDomains } = await pg.sql`
116
- SELECT domain, verification_type
117
- FROM email_domains
118
- WHERE organization_id = 1
119
- ORDER BY verification_type
120
- `;
121
- assert.deepEqual(emailDomains, [
122
- { domain: "thousandsons.world", verification_type: "refused" },
123
- ]);
124
- });
125
-
126
- it("should reject a pending domain", async () => {
127
- await pg.sql`
128
- INSERT INTO organizations
129
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
130
- VALUES
131
- (1, 'Black Legion', 'Black Legion Warband', '👁️', '4444-04-04', '4444-04-04')
132
- ;
133
- `;
134
- await pg.sql`
135
- INSERT INTO email_domains (organization_id, domain, verification_type)
136
- VALUES (1, 'blacklegion.world', 'not_verified_yet')
137
- `;
138
-
139
- await markDomainAsVerified({
140
- domain: "blacklegion.world",
141
- domain_verification_type: "refused",
142
- organization_id: 1,
143
- });
144
-
145
- const { rows: emailDomains } = await pg.sql`
146
- SELECT domain, verification_type
147
- FROM email_domains
148
- WHERE organization_id = 1
149
- ORDER BY verification_type
150
- `;
151
- assert.deepEqual(emailDomains, [
152
- { domain: "blacklegion.world", verification_type: "refused" },
153
- ]);
154
- });
155
-
156
- it("rejecting a domain should not demote an already domain-verified member", async () => {
157
- await pg.sql`
158
- INSERT INTO organizations
159
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
160
- VALUES
161
- (1, 'Word Bearers', 'Word Bearers Legion', '🔥', '4444-04-04', '4444-04-04')
162
- ;
163
- `;
164
- await pg.sql`
165
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
166
- VALUES (1, 'lorgar.aurelian@wordbearers.world', '4444-04-04', '4444-04-04', 'Lorgar', 'Aurelian', '0', 'Primarque')
167
- `;
168
- await pg.sql`
169
- INSERT INTO users_organizations
170
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
171
- VALUES
172
- (1, 1, '4444-04-04', '4444-04-04', false, 'domain')
173
- ;
174
- `;
175
- await pg.sql`
176
- INSERT INTO email_domains (organization_id, domain, verification_type)
177
- VALUES (1, 'wordbearers.world', 'not_verified_yet')
178
- `;
179
-
180
- await markDomainAsVerified({
181
- domain: "wordbearers.world",
182
- domain_verification_type: "refused",
183
- organization_id: 1,
184
- });
185
-
186
- const { rows: userLinks } = await pg.sql`
187
- SELECT user_id, verification_type
188
- FROM users_organizations
189
- WHERE organization_id = 1
190
- `;
191
- assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
192
- });
193
-
194
- it("approving a domain should only promote eligible member links", async () => {
195
- await pg.sql`
196
- INSERT INTO organizations
197
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
198
- VALUES
199
- (1, 'Emperor''s Children', 'Emperor''s Children Legion', '🎭', '4444-04-04', '4444-04-04')
200
- ;
201
- `;
202
- await pg.sql`
203
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
204
- VALUES
205
- (1, 'fulgrim@emperorschildren.world', '4444-04-04', '4444-04-04', 'Fulgrim', 'Primarque', '0', 'Primarque'),
206
- (2, 'lucius@emperorschildren.world', '4444-04-04', '4444-04-04', 'Lucius', 'The Eternal', '0', 'Champion')
207
- ;
208
- `;
209
- await pg.sql`
210
- INSERT INTO users_organizations
211
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
212
- VALUES
213
- (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
214
- (2, 1, '4444-04-04', '4444-04-04', false, 'organization_dirigeant')
215
- ;
216
- `;
217
- await pg.sql`
218
- INSERT INTO email_domains (organization_id, domain, verification_type)
219
- VALUES (1, 'emperorschildren.world', 'not_verified_yet')
220
- `;
221
-
222
- await markDomainAsVerified({
223
- domain: "emperorschildren.world",
224
- domain_verification_type: "verified",
225
- organization_id: 1,
226
- });
227
-
228
- const { rows: userLinks } = await pg.sql`
229
- SELECT user_id, verification_type
230
- FROM users_organizations
231
- WHERE organization_id = 1
232
- ORDER BY user_id
233
- `;
234
- assert.deepEqual(userLinks, [
235
- { user_id: 1, verification_type: "domain" },
236
- { user_id: 2, verification_type: "organization_dirigeant" },
237
- ]);
238
- });
239
-
240
- it("❎ throws NotFoundError for unknown organization", async () => {
241
- await assert.rejects(
242
- markDomainAsVerified({
243
- domain: "darkangels.world",
244
- domain_verification_type: "verified",
245
- organization_id: 999,
246
- }),
247
- new NotFoundError(""),
248
- );
249
- });
250
- });