@proconnect-gouv/proconnect.identite 1.7.1 → 2.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.
- package/CHANGELOG.md +6 -0
- package/dist/connectors/index.d.ts +110 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +45 -0
- package/dist/managers/organization/adapters/api_entreprise.d.ts +1 -1
- package/dist/managers/organization/mark-domain-as-verified.d.ts +2 -12
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
- package/dist/managers/organization/mark-domain-as-verified.js +9 -10
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +2 -9
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +1 -1
- package/dist/managers/user/assign-user-verification-type-to-domain.js +4 -3
- package/dist/types/organization-info.d.ts +1 -1
- package/package.json +1 -1
- package/src/connectors/index.ts +51 -0
- package/src/managers/organization/mark-domain-as-verified.test.ts +50 -64
- package/src/managers/organization/mark-domain-as-verified.ts +13 -33
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +87 -78
- package/src/managers/user/assign-user-verification-type-to-domain.ts +5 -16
- package/testing/index.ts +2 -0
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/src/managers/organization/mark-domain-as-verified.test.ts.snapshot +0 -53
|
@@ -1,97 +1,106 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
+
import { context, emptyDatabase, migrate, pg } from "#testing";
|
|
3
4
|
import assert from "node:assert/strict";
|
|
4
|
-
import { describe, it
|
|
5
|
+
import { before, beforeEach, describe, it } from "node:test";
|
|
5
6
|
import { assignUserVerificationTypeToDomainFactory } from "./assign-user-verification-type-to-domain.js";
|
|
6
7
|
|
|
7
8
|
//
|
|
8
9
|
|
|
10
|
+
const assignUserVerificationTypeToDomain =
|
|
11
|
+
assignUserVerificationTypeToDomainFactory(context);
|
|
12
|
+
|
|
9
13
|
describe("assignUserVerificationTypeToDomain", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
10
17
|
it("should update some organization members", async () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
// user from a different domain — should not be updated
|
|
26
|
+
await pg.sql`
|
|
27
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
+
VALUES (1, 'foo@bar.world', '4444-04-04', '4444-04-04', 'Foo', 'Bar', '0', 'None')
|
|
29
|
+
`;
|
|
30
|
+
// user matching domain but already "verified" — should not be updated
|
|
31
|
+
await pg.sql`
|
|
32
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
33
|
+
VALUES (2, 'foo@darkangels.world', '4444-04-04', '4444-04-04', 'Foo', 'DA', '0', 'None')
|
|
34
|
+
`;
|
|
35
|
+
// user with no_validation_means_available — should be updated
|
|
36
|
+
await pg.sql`
|
|
37
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
38
|
+
VALUES (3, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
|
|
39
|
+
`;
|
|
40
|
+
// user with no_verification_means_for_entreprise_unipersonnelle — should be updated
|
|
41
|
+
await pg.sql`
|
|
42
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
43
|
+
VALUES (4, 'cat.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Cat', 'El''Jonson', '0', 'Scout')
|
|
44
|
+
`;
|
|
45
|
+
// user with no_verification_means_for_small_association — should be updated
|
|
46
|
+
await pg.sql`
|
|
47
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
48
|
+
VALUES (5, 'tiger.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Tiger', 'El''Jonson', '0', 'Scout')
|
|
49
|
+
`;
|
|
50
|
+
// user with domain_not_verified_yet — should be updated
|
|
51
|
+
await pg.sql`
|
|
52
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
53
|
+
VALUES (6, 'mouse.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Mouse', 'El''Jonson', '0', 'Scout')
|
|
54
|
+
`;
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
// link all users to the organization
|
|
57
|
+
await pg.sql`
|
|
58
|
+
INSERT INTO users_organizations
|
|
59
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type, needs_official_contact_email_verification, official_contact_email_verification_token, official_contact_email_verification_sent_at)
|
|
60
|
+
VALUES
|
|
61
|
+
(1, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available', false, null, null),
|
|
62
|
+
(2, 1, '4444-04-04', '4444-04-04', false, 'verified', false, null, null),
|
|
63
|
+
(3, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available', false, null, null),
|
|
64
|
+
(4, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle', false, null, null),
|
|
65
|
+
(5, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_small_association', false, null, null),
|
|
66
|
+
(6, 1, '4444-04-04', '4444-04-04', false, 'domain_not_verified_yet', false, null, null)
|
|
67
|
+
;
|
|
68
|
+
`;
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
44,
|
|
69
|
-
{
|
|
70
|
-
verification_type: "domain",
|
|
71
|
-
},
|
|
72
|
-
]);
|
|
73
|
-
assert.deepEqual(mouse.arguments, [
|
|
74
|
-
111,
|
|
75
|
-
45,
|
|
76
|
-
{
|
|
77
|
-
verification_type: "domain",
|
|
78
|
-
},
|
|
70
|
+
await assignUserVerificationTypeToDomain(1, "darkangels.world");
|
|
71
|
+
|
|
72
|
+
// verify that the 4 matching users were updated to "domain"
|
|
73
|
+
const { rows } = await pg.sql`
|
|
74
|
+
SELECT user_id, verification_type
|
|
75
|
+
FROM users_organizations
|
|
76
|
+
WHERE organization_id = 1
|
|
77
|
+
ORDER BY user_id
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
assert.deepEqual(rows, [
|
|
81
|
+
{ user_id: 1, verification_type: "no_validation_means_available" }, // different domain
|
|
82
|
+
{ user_id: 2, verification_type: "verified" }, // already verified
|
|
83
|
+
{ user_id: 3, verification_type: "domain" },
|
|
84
|
+
{ user_id: 4, verification_type: "domain" },
|
|
85
|
+
{ user_id: 5, verification_type: "domain" },
|
|
86
|
+
{ user_id: 6, verification_type: "domain" },
|
|
79
87
|
]);
|
|
80
|
-
assert.equal(updateUserOrganizationLink.mock.callCount(), 4);
|
|
81
88
|
});
|
|
82
89
|
|
|
83
90
|
it("❎ should update nothing if no organization members", async () => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
91
|
+
await pg.sql`
|
|
92
|
+
INSERT INTO organizations
|
|
93
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
94
|
+
VALUES
|
|
95
|
+
(1, 'Empty', 'Empty Org', '🫥', '4444-04-04', '4444-04-04')
|
|
96
|
+
;
|
|
97
|
+
`;
|
|
92
98
|
|
|
93
|
-
await assignUserVerificationTypeToDomain(
|
|
99
|
+
await assignUserVerificationTypeToDomain(1, "darkangels.world");
|
|
94
100
|
|
|
95
|
-
|
|
101
|
+
const { rows } = await pg.sql`
|
|
102
|
+
SELECT * FROM users_organizations WHERE organization_id = 1
|
|
103
|
+
`;
|
|
104
|
+
assert.deepEqual(rows, []);
|
|
96
105
|
});
|
|
97
106
|
});
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
|
|
3
|
+
import type { Context } from "#src/connectors";
|
|
5
4
|
import { LinkTypes, SuperWeakLinkTypes, UnverifiedLinkTypes } from "#src/types";
|
|
6
5
|
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
7
6
|
import { match } from "ts-pattern";
|
|
8
7
|
|
|
9
8
|
//
|
|
10
9
|
|
|
11
|
-
type FactoryDependencies = {
|
|
12
|
-
getUsers: GetUsersByOrganizationHandler;
|
|
13
|
-
updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
10
|
export function assignUserVerificationTypeToDomainFactory({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}: FactoryDependencies) {
|
|
11
|
+
repository: { organizations, users_organizations },
|
|
12
|
+
}: Context) {
|
|
20
13
|
return async function assignUserVerificationTypeToDomain(
|
|
21
14
|
organization_id: number,
|
|
22
15
|
domain: string,
|
|
23
16
|
) {
|
|
24
|
-
const usersInOrganization = await getUsers(organization_id);
|
|
17
|
+
const usersInOrganization = await organizations.getUsers(organization_id);
|
|
25
18
|
|
|
26
19
|
await Promise.all(
|
|
27
20
|
usersInOrganization.map(
|
|
@@ -33,7 +26,7 @@ export function assignUserVerificationTypeToDomainFactory({
|
|
|
33
26
|
.with(...UnverifiedLinkTypes, ...SuperWeakLinkTypes, () => true)
|
|
34
27
|
.otherwise(() => false)
|
|
35
28
|
) {
|
|
36
|
-
return
|
|
29
|
+
return users_organizations.update(organization_id, id, {
|
|
37
30
|
verification_type: LinkTypes.enum.domain,
|
|
38
31
|
});
|
|
39
32
|
}
|
|
@@ -44,7 +37,3 @@ export function assignUserVerificationTypeToDomainFactory({
|
|
|
44
37
|
);
|
|
45
38
|
};
|
|
46
39
|
}
|
|
47
|
-
|
|
48
|
-
export type AssignUserVerificationTypeToDomainFactoryHandler = ReturnType<
|
|
49
|
-
typeof assignUserVerificationTypeToDomainFactory
|
|
50
|
-
>;
|
package/testing/index.ts
CHANGED
|
@@ -4,10 +4,12 @@ import { PGlite } from "@electric-sql/pglite";
|
|
|
4
4
|
import { noop } from "lodash-es";
|
|
5
5
|
import { runner } from "node-pg-migrate";
|
|
6
6
|
import { join } from "path";
|
|
7
|
+
import { createContext } from "../src/connectors/index.js";
|
|
7
8
|
|
|
8
9
|
//
|
|
9
10
|
|
|
10
11
|
export const pg = new PGlite();
|
|
12
|
+
export const context = createContext(pg as any);
|
|
11
13
|
|
|
12
14
|
export function migrate() {
|
|
13
15
|
return runner({
|