@proconnect-gouv/proconnect.identite 1.7.1 → 3.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 (29) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/connectors/index.d.ts +110 -0
  3. package/dist/connectors/index.d.ts.map +1 -0
  4. package/dist/connectors/index.js +45 -0
  5. package/dist/managers/certification/process-certification-dirigeant.d.ts +5 -8
  6. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  7. package/dist/managers/certification/process-certification-dirigeant.js +5 -5
  8. package/dist/managers/organization/adapters/api_entreprise.d.ts +1 -1
  9. package/dist/managers/organization/get-organization-info.d.ts +2 -2
  10. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  11. package/dist/managers/organization/mark-domain-as-verified.d.ts +2 -12
  12. package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
  13. package/dist/managers/organization/mark-domain-as-verified.js +9 -10
  14. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +2 -9
  15. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +1 -1
  16. package/dist/managers/user/assign-user-verification-type-to-domain.js +4 -3
  17. package/dist/types/organization-info.d.ts +1 -1
  18. package/package.json +4 -4
  19. package/src/connectors/index.ts +51 -0
  20. package/src/managers/certification/process-certification-dirigeant.test.ts +21 -21
  21. package/src/managers/certification/process-certification-dirigeant.ts +12 -15
  22. package/src/managers/organization/get-organization-info.ts +2 -4
  23. package/src/managers/organization/mark-domain-as-verified.test.ts +50 -64
  24. package/src/managers/organization/mark-domain-as-verified.ts +13 -33
  25. package/src/managers/user/assign-user-verification-type-to-domain.test.ts +87 -78
  26. package/src/managers/user/assign-user-verification-type-to-domain.ts +5 -16
  27. package/testing/index.ts +2 -0
  28. package/tsconfig.lib.tsbuildinfo +1 -1
  29. package/src/managers/organization/mark-domain-as-verified.test.ts.snapshot +0 -53
@@ -7,8 +7,8 @@ import {
7
7
  type IdentityVector,
8
8
  type Organization,
9
9
  } from "#src/types";
10
- import type { ApiEntrepriseInfogreffeRepository } from "@proconnect-gouv/proconnect.api_entreprise/api";
11
- import type { FindUniteLegaleBySirenHandler } from "@proconnect-gouv/proconnect.insee/api";
10
+ import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
11
+ import type { ApiInseeClient } from "@proconnect-gouv/proconnect.insee/api";
12
12
  import type { FindPouvoirsBySirenHandler } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
13
13
  import { match } from "ts-pattern";
14
14
  import z from "zod/v4";
@@ -21,13 +21,12 @@ import { certificationScore } from "./certification-score.js";
21
21
  //
22
22
 
23
23
  type ProcessCertificationDirigeantConfig = {
24
- ApiEntrepriseInfogreffeRepository: Pick<
25
- ApiEntrepriseInfogreffeRepository,
24
+ ApiEntrepriseClient: Pick<
25
+ ApiEntrepriseClient,
26
26
  "findMandatairesSociauxBySiren"
27
27
  >;
28
- EQUALITY_THRESHOLD?: number;
29
- InseeApiRepository: { findBySiren: FindUniteLegaleBySirenHandler };
30
- RegistreNationalEntreprisesApiRepository: {
28
+ InseeApiClient: ApiInseeClient;
29
+ RegistreNationalEntreprisesApiClient: {
31
30
  findPouvoirsBySiren: FindPouvoirsBySirenHandler;
32
31
  };
33
32
  };
@@ -61,14 +60,14 @@ export function getCertificationDirigeantDataSourceLabels(
61
60
 
62
61
  async function getMandatairesSociaux(
63
62
  {
64
- RegistreNationalEntreprisesApiRepository,
65
- ApiEntrepriseInfogreffeRepository,
63
+ RegistreNationalEntreprisesApiClient,
64
+ ApiEntrepriseClient,
66
65
  }: ProcessCertificationDirigeantConfig,
67
66
  siren: string,
68
67
  ) {
69
68
  try {
70
69
  const pouvoirs =
71
- await RegistreNationalEntreprisesApiRepository.findPouvoirsBySiren(siren);
70
+ await RegistreNationalEntreprisesApiClient.findPouvoirsBySiren(siren);
72
71
  const dirigeants = pouvoirs.map(RNE.toIdentityVector);
73
72
 
74
73
  return {
@@ -81,9 +80,7 @@ async function getMandatairesSociaux(
81
80
  } catch (error) {
82
81
  console.error(error);
83
82
  const mandataires =
84
- await ApiEntrepriseInfogreffeRepository.findMandatairesSociauxBySiren(
85
- siren,
86
- );
83
+ await ApiEntrepriseClient.findMandatairesSociauxBySiren(siren);
87
84
  const dirigeants = mandataires.map(ApiEntreprise.toIdentityVector);
88
85
 
89
86
  return {
@@ -132,7 +129,7 @@ function match_identity_to_dirigeant(
132
129
  export function processCertificationDirigeantFactory(
133
130
  config: ProcessCertificationDirigeantConfig,
134
131
  ) {
135
- const { InseeApiRepository } = config;
132
+ const { InseeApiClient } = config;
136
133
 
137
134
  return async function processCertificationDirigeant(
138
135
  organization: Organization,
@@ -166,7 +163,7 @@ export function processCertificationDirigeantFactory(
166
163
 
167
164
  const { dirigeants, source } = await match(preferredDataSource)
168
165
  .with("api.insee.fr/api-sirene/private", async () => ({
169
- dirigeants: await InseeApiRepository.findBySiren(siren)
166
+ dirigeants: await InseeApiClient.findBySiren(siren)
170
167
  .then(INSEE.toIdentityVector)
171
168
  .then((vector) => [vector]),
172
169
  source:
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { InvalidSiretError, NotFoundError } from "#src/errors";
4
4
  import { type OrganizationInfo } from "#src/types";
5
- import type { ApiEntrepriseInseeRepository } from "@proconnect-gouv/proconnect.api_entreprise/api";
5
+ import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
6
6
  import {
7
7
  ApiEntrepriseConnectionError,
8
8
  ApiEntrepriseInvalidSiret,
@@ -11,9 +11,7 @@ import * as ApiEntreprise from "./adapters/api_entreprise.js";
11
11
 
12
12
  //
13
13
 
14
- export function getOrganizationInfoFactory(
15
- config: ApiEntrepriseInseeRepository,
16
- ) {
14
+ export function getOrganizationInfoFactory(config: ApiEntrepriseClient) {
17
15
  const { findBySiren, findBySiret } = config;
18
16
 
19
17
  return async function getOrganizationInfo(
@@ -1,89 +1,75 @@
1
+ //
2
+
1
3
  import { NotFoundError } from "#src/errors";
2
- import {
3
- type AddDomainHandler,
4
- type DeleteEmailDomainsByVerificationTypesHandler,
5
- } from "#src/repositories/email-domain";
6
- import type {
7
- FindByIdHandler,
8
- GetUsersByOrganizationHandler,
9
- } from "#src/repositories/organization";
10
- import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
11
- import type { BaseUserOrganizationLink, Organization, User } from "#src/types";
4
+ import { context, emptyDatabase, migrate, pg } from "#testing";
12
5
  import assert from "node:assert/strict";
13
- import { describe, it, mock } from "node:test";
6
+ import { before, beforeEach, describe, it } from "node:test";
14
7
  import { markDomainAsVerifiedFactory } from "./mark-domain-as-verified.js";
15
8
 
16
9
  //
17
10
 
11
+ const markDomainAsVerified = markDomainAsVerifiedFactory(context);
12
+
18
13
  describe("markDomainAsVerified", () => {
19
- it("should update organization members", async (t) => {
20
- const addDomain = mock.fn<AddDomainHandler>(() =>
21
- Promise.resolve({} as any),
22
- );
23
- const deleteEmailDomainsByVerificationTypes =
24
- mock.fn<DeleteEmailDomainsByVerificationTypesHandler>(() =>
25
- Promise.resolve({} as any),
26
- );
27
- const updateUserOrganizationLink =
28
- mock.fn<UpdateUserOrganizationLinkHandler>(() =>
29
- Promise.resolve({} as any),
30
- );
14
+ before(migrate);
15
+ beforeEach(emptyDatabase);
31
16
 
32
- const markDomainAsVerified = markDomainAsVerifiedFactory({
33
- addDomain,
34
- deleteEmailDomainsByVerificationTypes,
35
- findOrganizationById: mock.fn<FindByIdHandler>(() =>
36
- Promise.resolve({ id: 42 } as Organization),
37
- ),
38
- getUsers: mock.fn<GetUsersByOrganizationHandler>(() =>
39
- Promise.resolve([
40
- {
41
- id: 42,
42
- email: "lion.eljonson@darkangels.world",
43
- verification_type:
44
- "no_verification_means_for_entreprise_unipersonnelle",
45
- } as User & BaseUserOrganizationLink,
46
- ]),
47
- ),
48
- updateUserOrganizationLink,
49
- });
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, needs_official_contact_email_verification, official_contact_email_verification_token, official_contact_email_verification_sent_at)
32
+ VALUES
33
+ (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle', false, null, null)
34
+ ;
35
+ `;
36
+ await pg.sql`
37
+ INSERT INTO email_domains (organization_id, domain, verification_type)
38
+ VALUES (1, 'darkangels.world', 'not_verified_yet')
39
+ `;
50
40
 
51
41
  await markDomainAsVerified({
52
42
  domain: "darkangels.world",
53
43
  domain_verification_type: "verified",
54
- organization_id: 42,
44
+ organization_id: 1,
55
45
  });
56
46
 
57
- await t.test("should call updateUserOrganizationLink with", async (t) => {
58
- t.assert.snapshot(updateUserOrganizationLink.mock.calls);
59
- });
47
+ // user verification_type should be updated to "domain"
48
+ const { rows: userLinks } = await pg.sql`
49
+ SELECT user_id, verification_type
50
+ FROM users_organizations
51
+ WHERE organization_id = 1
52
+ `;
53
+ assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
60
54
 
61
- await t.test(
62
- "should call deleteEmailDomainsByVerificationTypes with",
63
- async (t) => {
64
- t.assert.snapshot(deleteEmailDomainsByVerificationTypes.mock.calls);
65
- },
66
- );
67
-
68
- await t.test("should call addDomain with", async (t) => {
69
- t.assert.snapshot(addDomain.mock.calls);
70
- });
55
+ // old email_domain records should be replaced with "verified"
56
+ const { rows: emailDomains } = await pg.sql`
57
+ SELECT domain, verification_type
58
+ FROM email_domains
59
+ WHERE organization_id = 1
60
+ ORDER BY verification_type
61
+ `;
62
+ assert.deepEqual(emailDomains, [
63
+ { domain: "darkangels.world", verification_type: "verified" },
64
+ ]);
71
65
  });
72
66
 
73
67
  it("❎ throws NotFoundError for unknown organization", async () => {
74
- const markDomainAsVerified = markDomainAsVerifiedFactory({
75
- addDomain: () => Promise.reject(),
76
- deleteEmailDomainsByVerificationTypes: () => Promise.reject(),
77
- findOrganizationById: () => Promise.resolve(undefined),
78
- getUsers: () => Promise.reject(),
79
- updateUserOrganizationLink: () => Promise.reject(),
80
- });
81
-
82
68
  await assert.rejects(
83
69
  markDomainAsVerified({
84
70
  domain: "darkangels.world",
85
71
  domain_verification_type: "verified",
86
- organization_id: 42,
72
+ organization_id: 999,
87
73
  }),
88
74
  new NotFoundError(""),
89
75
  );
@@ -1,16 +1,8 @@
1
1
  //
2
2
 
3
+ import type { Context } from "#src/connectors";
3
4
  import { NotFoundError } from "#src/errors";
4
5
  import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
5
- import type {
6
- AddDomainHandler,
7
- DeleteEmailDomainsByVerificationTypesHandler,
8
- } from "#src/repositories/email-domain";
9
- import type {
10
- FindByIdHandler,
11
- GetUsersByOrganizationHandler,
12
- } from "#src/repositories/organization";
13
- import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
14
6
  import {
15
7
  type EmailDomainApprovedVerificationType,
16
8
  EmailDomainApprovedVerificationTypes,
@@ -26,26 +18,14 @@ import { match } from "ts-pattern";
26
18
 
27
19
  //
28
20
 
29
- type FactoryDependencies = {
30
- addDomain: AddDomainHandler;
31
- deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
32
- findOrganizationById: FindByIdHandler;
33
- getUsers: GetUsersByOrganizationHandler;
34
- updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
35
- };
36
-
37
- export function markDomainAsVerifiedFactory({
38
- addDomain,
39
- deleteEmailDomainsByVerificationTypes,
40
- findOrganizationById,
41
- getUsers,
42
- updateUserOrganizationLink,
43
- }: FactoryDependencies) {
21
+ export function markDomainAsVerifiedFactory(context: Context) {
44
22
  const assignUserVerificationTypeToDomain =
45
- assignUserVerificationTypeToDomainFactory({
46
- getUsers,
47
- updateUserOrganizationLink,
48
- });
23
+ assignUserVerificationTypeToDomainFactory(context);
24
+
25
+ const {
26
+ repository: { email_domains, organizations },
27
+ } = context;
28
+
49
29
  return async function markDomainAsVerified({
50
30
  organization_id,
51
31
  domain,
@@ -55,7 +35,7 @@ export function markDomainAsVerifiedFactory({
55
35
  domain: string;
56
36
  domain_verification_type: EmailDomainNoPendingVerificationType;
57
37
  }) {
58
- const organization = await findOrganizationById(organization_id);
38
+ const organization = await organizations.findById(organization_id);
59
39
 
60
40
  if (isEmpty(organization)) {
61
41
  throw new NotFoundError();
@@ -94,7 +74,7 @@ export function markDomainAsVerifiedFactory({
94
74
  domain: string;
95
75
  domain_verification_type: EmailDomainApprovedVerificationType;
96
76
  }) {
97
- await deleteEmailDomainsByVerificationTypes({
77
+ await email_domains.deleteEmailDomainsByVerificationTypes({
98
78
  organization_id,
99
79
  domain,
100
80
  domain_verification_types: [
@@ -102,7 +82,7 @@ export function markDomainAsVerifiedFactory({
102
82
  ...EmailDomainPendingVerificationTypes,
103
83
  ],
104
84
  });
105
- return addDomain({
85
+ return email_domains.addDomain({
106
86
  organization_id,
107
87
  domain,
108
88
  verification_type:
@@ -119,7 +99,7 @@ export function markDomainAsVerifiedFactory({
119
99
  domain: string;
120
100
  domain_verification_type: EmailDomainRejectedVerificationType;
121
101
  }) {
122
- await deleteEmailDomainsByVerificationTypes({
102
+ await email_domains.deleteEmailDomainsByVerificationTypes({
123
103
  organization_id,
124
104
  domain,
125
105
  domain_verification_types: [
@@ -127,7 +107,7 @@ export function markDomainAsVerifiedFactory({
127
107
  ...EmailDomainRejectedVerificationTypes,
128
108
  ],
129
109
  });
130
- return addDomain({
110
+ return email_domains.addDomain({
131
111
  organization_id,
132
112
  domain,
133
113
  verification_type:
@@ -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, mock } from "node:test";
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
- const updateUserOrganizationLink = mock.fn(() =>
12
- Promise.resolve({} as any),
13
- );
14
- const assignUserVerificationTypeToDomain =
15
- assignUserVerificationTypeToDomainFactory({
16
- getUsers: () =>
17
- Promise.resolve([
18
- { email: "foo@bar.world" },
19
- { email: "foo@darkangels.world" },
20
- {
21
- email: "foo@darkangels.world",
22
- verification_type: "verified",
23
- },
24
- {
25
- id: 42,
26
- email: "lion.eljonson@darkangels.world",
27
- verification_type: "no_validation_means_available",
28
- },
29
- {
30
- id: 43,
31
- email: "cat.eljonson@darkangels.world",
32
- verification_type:
33
- "no_verification_means_for_entreprise_unipersonnelle",
34
- },
35
- {
36
- id: 44,
37
- email: "tiger.eljonson@darkangels.world",
38
- verification_type: "no_verification_means_for_small_association",
39
- },
40
- {
41
- id: 45,
42
- email: "mouse.eljonson@darkangels.world",
43
- verification_type: "domain_not_verified_yet",
44
- },
45
- ] as any),
46
- updateUserOrganizationLink,
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
- await assignUserVerificationTypeToDomain(111, "darkangels.world");
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
- const [lion, cat, tiger, mouse] = updateUserOrganizationLink.mock.calls;
52
- assert.deepEqual(lion.arguments, [
53
- 111,
54
- 42,
55
- {
56
- verification_type: "domain",
57
- },
58
- ]);
59
- assert.deepEqual(cat.arguments, [
60
- 111,
61
- 43,
62
- {
63
- verification_type: "domain",
64
- },
65
- ]);
66
- assert.deepEqual(tiger.arguments, [
67
- 111,
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
- const updateUserOrganizationLink = mock.fn(() =>
85
- Promise.reject(new Error("💣")),
86
- );
87
- const assignUserVerificationTypeToDomain =
88
- assignUserVerificationTypeToDomainFactory({
89
- getUsers: () => Promise.resolve([]),
90
- updateUserOrganizationLink,
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(42, "darkangels.world");
99
+ await assignUserVerificationTypeToDomain(1, "darkangels.world");
94
100
 
95
- assert.deepEqual(updateUserOrganizationLink.mock.calls, []);
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 { GetUsersByOrganizationHandler } from "#src/repositories/organization";
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
- getUsers,
18
- updateUserOrganizationLink,
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 updateUserOrganizationLink(organization_id, id, {
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({