@proconnect-gouv/proconnect.identite 10.0.2 → 10.1.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 +49 -45
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +31 -53
- package/dist/managers/organization/adapters/api_entreprise.d.ts +1 -1
- 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 +3 -3
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts +3 -0
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts.map +1 -0
- package/dist/repositories/authenticator/{get-authenticators-by-user-id.js → find-authenticators-by-user-id.js} +2 -2
- package/dist/repositories/authenticator/index.d.ts +1 -1
- package/dist/repositories/authenticator/index.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.js +1 -1
- package/dist/repositories/authenticator/update-authenticator.d.ts +1 -2
- package/dist/repositories/authenticator/update-authenticator.d.ts.map +1 -1
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.js +2 -2
- package/dist/repositories/{user/get-franceconnect-user-info.d.ts → franceconnect_userinfo/find-franceconnect-userinfo.d.ts} +2 -3
- package/dist/repositories/franceconnect_userinfo/find-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user/get-franceconnect-user-info.js → franceconnect_userinfo/find-franceconnect-userinfo.js} +2 -2
- package/dist/repositories/franceconnect_userinfo/index.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -0
- package/dist/repositories/franceconnect_userinfo/index.js +3 -0
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts +3 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.js +12 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.js +13 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts +4 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/index.js +4 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.js +19 -0
- package/dist/repositories/organization/find-by-user-id.d.ts +0 -3
- package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
- package/dist/repositories/organization/find-by-user-id.js +10 -14
- package/dist/repositories/organization/find-organization-by-id.d.ts +4 -0
- package/dist/repositories/organization/find-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/{find-by-id.js → find-organization-by-id.js} +2 -2
- package/dist/repositories/organization/{get-users-by-organization.d.ts → find-users-by-organization.d.ts} +2 -6
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +1 -0
- package/dist/repositories/organization/find-users-by-organization.js +19 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts +3 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/get-organization-by-id.js +15 -0
- package/dist/repositories/organization/index.d.ts +3 -5
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +3 -5
- package/dist/repositories/user/index.d.ts +0 -3
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -3
- package/dist/repositories/{organization/link-user-to-organization.d.ts → user_organisation/create-user-organization.d.ts} +2 -6
- package/dist/repositories/user_organisation/create-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization/link-user-to-organization.js → user_organisation/create-user-organization.js} +2 -3
- package/dist/repositories/user_organisation/delete-user-organization.d.ts +3 -0
- package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization → user_organisation}/delete-user-organization.js +4 -2
- package/dist/repositories/{organization/get-user-organization-link.d.ts → user_organisation/find-user-organization.d.ts} +3 -6
- package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -0
- package/dist/repositories/user_organisation/find-user-organization.js +20 -0
- package/dist/repositories/user_organisation/index.d.ts +5 -0
- package/dist/repositories/user_organisation/index.d.ts.map +1 -0
- package/dist/repositories/user_organisation/index.js +4 -0
- package/dist/repositories/{user/update-user-organization-link.d.ts → user_organisation/update-user-organization.d.ts} +3 -7
- package/dist/repositories/user_organisation/update-user-organization.d.ts.map +1 -0
- package/dist/repositories/{user/update-user-organization-link.js → user_organisation/update-user-organization.js} +2 -2
- package/dist/types/authenticator.d.ts +3 -1
- package/dist/types/authenticator.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/official-contact-email-verification.d.ts +23 -0
- package/dist/types/official-contact-email-verification.d.ts.map +1 -0
- package/dist/types/official-contact-email-verification.js +15 -0
- package/dist/types/organization-info.d.ts +2 -1
- package/dist/types/organization-info.d.ts.map +1 -1
- package/dist/types/organization-info.js +1 -0
- package/dist/types/organization.d.ts +1 -1
- package/dist/types/organization.d.ts.map +1 -1
- package/dist/types/user-organization-link.d.ts +5 -7
- package/dist/types/user-organization-link.d.ts.map +1 -1
- package/dist/types/user-organization-link.js +4 -6
- package/package.json +1 -1
- package/src/connectors/index.ts +83 -53
- package/src/managers/organization/mark-domain-as-verified.test.ts +2 -3
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +7 -8
- package/src/managers/user/assign-user-verification-type-to-domain.ts +8 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.test.ts → find-authenticators-by-user-id.test.ts} +5 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.ts → find-authenticators-by-user-id.ts} +2 -2
- package/src/repositories/authenticator/index.ts +1 -1
- package/src/repositories/authenticator/update-authenticator.ts +1 -1
- package/src/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.test.ts +7 -7
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +21 -0
- package/src/repositories/{user/get-franceconnect-user-info.test.ts → franceconnect_userinfo/find-franceconnect-userinfo.test.ts} +5 -5
- package/src/repositories/{user/get-franceconnect-user-info.ts → franceconnect_userinfo/find-franceconnect-userinfo.ts} +2 -6
- package/src/repositories/franceconnect_userinfo/index.ts +3 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.test.ts +106 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.ts +29 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.test.ts +136 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.ts +31 -0
- package/src/repositories/official-contact-email-verification/index.ts +5 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.test.ts +170 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.ts +38 -0
- package/src/repositories/organization/find-by-user-id.test.ts +5 -6
- package/src/repositories/organization/find-by-user-id.test.ts.snapshot +3 -12
- package/src/repositories/organization/find-by-user-id.ts +10 -14
- package/src/repositories/organization/{find-by-id.test.ts → find-organization-by-id.test.ts} +4 -4
- package/src/repositories/organization/{find-by-id.ts → find-organization-by-id.ts} +3 -3
- package/src/repositories/organization/{get-users-by-organization.test.ts → find-users-by-organization.test.ts} +9 -8
- package/src/repositories/organization/{get-users-by-organization.test.ts.snapshot → find-users-by-organization.test.ts.snapshot} +2 -5
- package/src/repositories/organization/find-users-by-organization.ts +38 -0
- package/src/repositories/organization/get-organization-by-id.test.ts +37 -0
- package/src/repositories/organization/get-organization-by-id.ts +19 -0
- package/src/repositories/organization/index.ts +3 -5
- package/src/repositories/user/index.ts +0 -3
- package/src/repositories/{organization/link-user-to-organization.test.ts → user_organisation/create-user-organization.test.ts} +2 -2
- package/src/repositories/{organization/link-user-to-organization.test.ts.snapshot → user_organisation/create-user-organization.test.ts.snapshot} +0 -6
- package/src/repositories/{organization/link-user-to-organization.ts → user_organisation/create-user-organization.ts} +1 -7
- package/src/repositories/{organization → user_organisation}/delete-user-organization.ts +6 -7
- package/src/repositories/{organization/get-user-organization-link.test.ts → user_organisation/find-user-organization.test.ts} +5 -5
- package/src/repositories/user_organisation/find-user-organization.ts +35 -0
- package/src/repositories/user_organisation/index.ts +4 -0
- package/src/repositories/{user/update-user-organization-link.test.ts → user_organisation/update-user-organization.test.ts} +10 -8
- package/src/repositories/{user/update-user-organization-link.ts → user_organisation/update-user-organization.ts} +9 -9
- package/src/services/organization/compute-service-public-info.test.ts +10 -0
- package/src/types/authenticator.ts +10 -5
- package/src/types/index.ts +1 -0
- package/src/types/official-contact-email-verification.ts +32 -0
- package/src/types/organization-info.ts +1 -1
- package/src/types/organization.ts +18 -1
- package/src/types/user-organization-link.ts +9 -8
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts +0 -3
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts.map +0 -1
- package/dist/repositories/organization/delete-user-organization.d.ts +0 -6
- package/dist/repositories/organization/delete-user-organization.d.ts.map +0 -1
- package/dist/repositories/organization/find-by-id.d.ts +0 -4
- package/dist/repositories/organization/find-by-id.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.js +0 -23
- package/dist/repositories/organization/get-users-by-organization.d.ts.map +0 -1
- package/dist/repositories/organization/get-users-by-organization.js +0 -23
- package/dist/repositories/organization/link-user-to-organization.d.ts.map +0 -1
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts +0 -4
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/user/get-franceconnect-user-info.d.ts.map +0 -1
- package/dist/repositories/user/update-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/user/upsert-franceconnect-userinfo.d.ts.map +0 -1
- package/src/repositories/organization/get-user-organization-link.ts +0 -34
- package/src/repositories/organization/get-users-by-organization.ts +0 -46
- package/src/repositories/user/delete-franceconnect-userinfo.ts +0 -21
- package/tsconfig.lib.tsbuildinfo +0 -1
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.d.ts +0 -0
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.js +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.test.ts +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.ts +0 -0
- /package/src/repositories/{organization → user_organisation}/delete-user-organization.test.ts +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { findOfficialContactEmailVerificationFactory } from "./find-official-contact-email-verification.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const findOfficialContactEmailVerification =
|
|
11
|
+
findOfficialContactEmailVerificationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("findOfficialContactEmailVerificationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should return undefined when not found", async () => {
|
|
18
|
+
const verification = await findOfficialContactEmailVerification({
|
|
19
|
+
organization_id: 42,
|
|
20
|
+
user_id: 42,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
assert.equal(verification, undefined);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should find the official contact email verification", async () => {
|
|
27
|
+
await pg.sql`
|
|
28
|
+
INSERT INTO organizations
|
|
29
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
30
|
+
VALUES
|
|
31
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
32
|
+
;
|
|
33
|
+
`;
|
|
34
|
+
await pg.sql`
|
|
35
|
+
INSERT INTO users
|
|
36
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
37
|
+
VALUES
|
|
38
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
39
|
+
;
|
|
40
|
+
`;
|
|
41
|
+
await pg.sql`
|
|
42
|
+
INSERT INTO official_contact_email_verifications
|
|
43
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
44
|
+
VALUES
|
|
45
|
+
(1, 1, '666666', '4444-04-04', '4444-04-01', '4444-04-02')
|
|
46
|
+
;
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const verification = await findOfficialContactEmailVerification({
|
|
50
|
+
organization_id: 1,
|
|
51
|
+
user_id: 1,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
assert.deepEqual(verification, {
|
|
55
|
+
created_at: new Date("4444-04-01"),
|
|
56
|
+
organization_id: 1,
|
|
57
|
+
sent_at: new Date("4444-04-04"),
|
|
58
|
+
token: "666666",
|
|
59
|
+
updated_at: new Date("4444-04-02"),
|
|
60
|
+
user_id: 1,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("should find an official contact email verification without token nor sent_at", async () => {
|
|
65
|
+
await pg.sql`
|
|
66
|
+
INSERT INTO organizations
|
|
67
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
68
|
+
VALUES
|
|
69
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
70
|
+
;
|
|
71
|
+
`;
|
|
72
|
+
await pg.sql`
|
|
73
|
+
INSERT INTO users
|
|
74
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
75
|
+
VALUES
|
|
76
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
77
|
+
;
|
|
78
|
+
`;
|
|
79
|
+
await pg.sql`
|
|
80
|
+
INSERT INTO official_contact_email_verifications
|
|
81
|
+
(user_id, organization_id, created_at, updated_at)
|
|
82
|
+
VALUES
|
|
83
|
+
(1, 1, '4444-04-01', '4444-04-02')
|
|
84
|
+
;
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
const verification = await findOfficialContactEmailVerification({
|
|
88
|
+
organization_id: 1,
|
|
89
|
+
user_id: 1,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
assert.deepEqual(verification, {
|
|
93
|
+
created_at: new Date("4444-04-01"),
|
|
94
|
+
organization_id: 1,
|
|
95
|
+
sent_at: null,
|
|
96
|
+
token: null,
|
|
97
|
+
updated_at: new Date("4444-04-02"),
|
|
98
|
+
user_id: 1,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("should find the verification of the given user and organization only", async () => {
|
|
103
|
+
await pg.sql`
|
|
104
|
+
INSERT INTO organizations
|
|
105
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
106
|
+
VALUES
|
|
107
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19'),
|
|
108
|
+
('Ultramar', 'Ultramarines', 2, '🔵', '1967-12-19', '1967-12-19')
|
|
109
|
+
;
|
|
110
|
+
`;
|
|
111
|
+
await pg.sql`
|
|
112
|
+
INSERT INTO users
|
|
113
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
114
|
+
VALUES
|
|
115
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'),
|
|
116
|
+
(2, 'roboute.guilliman@ultramarines.world', '4444-04-04', '4444-04-04', 'roboute', 'guilliman', 'xiii', 'primarque')
|
|
117
|
+
;
|
|
118
|
+
`;
|
|
119
|
+
await pg.sql`
|
|
120
|
+
INSERT INTO official_contact_email_verifications
|
|
121
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
122
|
+
VALUES
|
|
123
|
+
(1, 1, '111111', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
124
|
+
(1, 2, '222222', '4444-04-04', '4444-04-04', '4444-04-04'),
|
|
125
|
+
(2, 1, '333333', '4444-04-04', '4444-04-04', '4444-04-04')
|
|
126
|
+
;
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
const verification = await findOfficialContactEmailVerification({
|
|
130
|
+
organization_id: 2,
|
|
131
|
+
user_id: 1,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
assert.equal(verification?.token, "222222");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DatabaseContext,
|
|
5
|
+
FindOfficialContactEmailVerification,
|
|
6
|
+
OfficialContactEmailVerification,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import { type QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function findOfficialContactEmailVerificationFactory({
|
|
13
|
+
pg,
|
|
14
|
+
}: DatabaseContext) {
|
|
15
|
+
return async function findOfficialContactEmailVerification({
|
|
16
|
+
organization_id,
|
|
17
|
+
user_id,
|
|
18
|
+
}: FindOfficialContactEmailVerification) {
|
|
19
|
+
const { rows }: QueryResult<OfficialContactEmailVerification> =
|
|
20
|
+
await pg.query(
|
|
21
|
+
`
|
|
22
|
+
SELECT *
|
|
23
|
+
FROM official_contact_email_verifications
|
|
24
|
+
WHERE organization_id = $1
|
|
25
|
+
AND user_id = $2;`,
|
|
26
|
+
[organization_id, user_id],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return rows.shift();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { upsertOfficialContactEmailVerificationFactory } from "./upsert-official-contact-email-verification.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const upsertOfficialContactEmailVerification =
|
|
11
|
+
upsertOfficialContactEmailVerificationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("upsertOfficialContactEmailVerificationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should insert an official contact email verification", async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO organizations
|
|
20
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
21
|
+
VALUES
|
|
22
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO users
|
|
27
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const { created_at, updated_at, ...verification } =
|
|
34
|
+
await upsertOfficialContactEmailVerification({
|
|
35
|
+
organization_id: 1,
|
|
36
|
+
sent_at: new Date("4444-04-04"),
|
|
37
|
+
token: "666666",
|
|
38
|
+
user_id: 1,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
assert.deepEqual(verification, {
|
|
42
|
+
organization_id: 1,
|
|
43
|
+
sent_at: new Date("4444-04-04"),
|
|
44
|
+
token: "666666",
|
|
45
|
+
user_id: 1,
|
|
46
|
+
});
|
|
47
|
+
assert.ok(created_at instanceof Date);
|
|
48
|
+
assert.deepEqual(created_at, updated_at);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("should insert an official contact email verification without token nor sent_at", async () => {
|
|
52
|
+
await pg.sql`
|
|
53
|
+
INSERT INTO organizations
|
|
54
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
55
|
+
VALUES
|
|
56
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
57
|
+
;
|
|
58
|
+
`;
|
|
59
|
+
await pg.sql`
|
|
60
|
+
INSERT INTO users
|
|
61
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
62
|
+
VALUES
|
|
63
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
64
|
+
;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const { created_at, updated_at, ...verification } =
|
|
68
|
+
await upsertOfficialContactEmailVerification({
|
|
69
|
+
organization_id: 1,
|
|
70
|
+
sent_at: null,
|
|
71
|
+
token: null,
|
|
72
|
+
user_id: 1,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
assert.deepEqual(verification, {
|
|
76
|
+
organization_id: 1,
|
|
77
|
+
sent_at: null,
|
|
78
|
+
token: null,
|
|
79
|
+
user_id: 1,
|
|
80
|
+
});
|
|
81
|
+
assert.ok(created_at instanceof Date);
|
|
82
|
+
assert.deepEqual(created_at, updated_at);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("should update the existing official contact email verification", async () => {
|
|
86
|
+
await pg.sql`
|
|
87
|
+
INSERT INTO organizations
|
|
88
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
89
|
+
VALUES
|
|
90
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
91
|
+
;
|
|
92
|
+
`;
|
|
93
|
+
await pg.sql`
|
|
94
|
+
INSERT INTO users
|
|
95
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
96
|
+
VALUES
|
|
97
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
98
|
+
;
|
|
99
|
+
`;
|
|
100
|
+
await pg.sql`
|
|
101
|
+
INSERT INTO official_contact_email_verifications
|
|
102
|
+
(user_id, organization_id, token, sent_at, created_at, updated_at)
|
|
103
|
+
VALUES
|
|
104
|
+
(1, 1, '111111', '1967-12-19', '1967-12-19', '1967-12-19')
|
|
105
|
+
;
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const { created_at, updated_at, ...verification } =
|
|
109
|
+
await upsertOfficialContactEmailVerification({
|
|
110
|
+
organization_id: 1,
|
|
111
|
+
sent_at: new Date("4444-04-04"),
|
|
112
|
+
token: "666666",
|
|
113
|
+
user_id: 1,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(verification, {
|
|
117
|
+
organization_id: 1,
|
|
118
|
+
sent_at: new Date("4444-04-04"),
|
|
119
|
+
token: "666666",
|
|
120
|
+
user_id: 1,
|
|
121
|
+
});
|
|
122
|
+
assert.deepEqual(created_at, new Date("1967-12-19"));
|
|
123
|
+
assert.ok(updated_at > new Date("1967-12-19"));
|
|
124
|
+
|
|
125
|
+
const { rows } = await pg.sql`
|
|
126
|
+
SELECT count(*)::int AS count FROM official_contact_email_verifications;
|
|
127
|
+
`;
|
|
128
|
+
assert.deepEqual(rows, [{ count: 1 }]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("❎ fail to insert a verification for an unknown user", async () => {
|
|
132
|
+
await pg.sql`
|
|
133
|
+
INSERT INTO organizations
|
|
134
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
135
|
+
VALUES
|
|
136
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
137
|
+
;
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
await assert.rejects(
|
|
141
|
+
upsertOfficialContactEmailVerification({
|
|
142
|
+
organization_id: 1,
|
|
143
|
+
sent_at: null,
|
|
144
|
+
token: "666666",
|
|
145
|
+
user_id: 42,
|
|
146
|
+
}),
|
|
147
|
+
`error: insert or update on table "official_contact_email_verifications" violates foreign key constraint "official_contact_email_verifications_user_id_fkey"`,
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("❎ fail to insert a verification for an unknown organization", async () => {
|
|
152
|
+
await pg.sql`
|
|
153
|
+
INSERT INTO users
|
|
154
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
155
|
+
VALUES
|
|
156
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
157
|
+
;
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
await assert.rejects(
|
|
161
|
+
upsertOfficialContactEmailVerification({
|
|
162
|
+
organization_id: 42,
|
|
163
|
+
sent_at: null,
|
|
164
|
+
token: "666666",
|
|
165
|
+
user_id: 1,
|
|
166
|
+
}),
|
|
167
|
+
`error: insert or update on table "official_contact_email_verifications" violates foreign key constraint "official_contact_email_verifications_organization_id_fkey"`,
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
BaseOfficialContactEmailVerification,
|
|
5
|
+
DatabaseContext,
|
|
6
|
+
OfficialContactEmailVerification,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
export function upsertOfficialContactEmailVerificationFactory({
|
|
12
|
+
pg,
|
|
13
|
+
}: DatabaseContext) {
|
|
14
|
+
return async function upsertOfficialContactEmailVerification({
|
|
15
|
+
organization_id,
|
|
16
|
+
user_id,
|
|
17
|
+
token,
|
|
18
|
+
sent_at,
|
|
19
|
+
}: BaseOfficialContactEmailVerification) {
|
|
20
|
+
const { rows } = await pg.query<OfficialContactEmailVerification>(
|
|
21
|
+
`
|
|
22
|
+
INSERT INTO official_contact_email_verifications(created_at, updated_at, organization_id, user_id, token, sent_at)
|
|
23
|
+
VALUES (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, $1, $2, $3, $4)
|
|
24
|
+
ON CONFLICT (organization_id, user_id)
|
|
25
|
+
DO UPDATE
|
|
26
|
+
SET organization_id = EXCLUDED.organization_id,
|
|
27
|
+
user_id = EXCLUDED.user_id,
|
|
28
|
+
token = EXCLUDED.token,
|
|
29
|
+
sent_at = EXCLUDED.sent_at,
|
|
30
|
+
updated_at = CURRENT_TIMESTAMP
|
|
31
|
+
RETURNING *
|
|
32
|
+
`,
|
|
33
|
+
[organization_id, user_id, token, sent_at],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return rows.shift()!;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -59,12 +59,11 @@ async function seed() {
|
|
|
59
59
|
|
|
60
60
|
await pg.sql`
|
|
61
61
|
INSERT INTO users_organizations
|
|
62
|
-
|
|
63
|
-
VALUES
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial', false, 'imperial_token_6', '2023-07-06', true)
|
|
62
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type, has_been_greeted)
|
|
63
|
+
VALUES (1, 1, '2023-01-25', '2024-02-20', false, 'necron', true),
|
|
64
|
+
(1, 3, '2023-04-01', '2024-05-05', true, 'alliance', false),
|
|
65
|
+
(2, 2, '2023-03-01', '2024-04-01', false, 'necron', true),
|
|
66
|
+
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial', true)
|
|
68
67
|
;
|
|
69
68
|
`;
|
|
70
69
|
}
|
|
@@ -27,10 +27,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
27
27
|
"is_external": false,
|
|
28
28
|
"verification_type": "necron",
|
|
29
29
|
"verified_at": null,
|
|
30
|
-
"has_been_greeted": true
|
|
31
|
-
"needs_official_contact_email_verification": false,
|
|
32
|
-
"official_contact_email_verification_token": "necron_token_1",
|
|
33
|
-
"official_contact_email_verification_sent_at": "2023-01-26T00:00:00.000Z"
|
|
30
|
+
"has_been_greeted": true
|
|
34
31
|
},
|
|
35
32
|
{
|
|
36
33
|
"id": 3,
|
|
@@ -59,10 +56,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
59
56
|
"is_external": true,
|
|
60
57
|
"verification_type": "alliance",
|
|
61
58
|
"verified_at": null,
|
|
62
|
-
"has_been_greeted": false
|
|
63
|
-
"needs_official_contact_email_verification": true,
|
|
64
|
-
"official_contact_email_verification_token": "alliance_token_1",
|
|
65
|
-
"official_contact_email_verification_sent_at": "2023-04-02T00:00:00.000Z"
|
|
59
|
+
"has_been_greeted": false
|
|
66
60
|
}
|
|
67
61
|
]
|
|
68
62
|
`;
|
|
@@ -96,10 +90,7 @@ exports[`findByUserIdFactory > should return single organization when user has o
|
|
|
96
90
|
"is_external": false,
|
|
97
91
|
"verification_type": "imperial",
|
|
98
92
|
"verified_at": null,
|
|
99
|
-
"has_been_greeted": true
|
|
100
|
-
"needs_official_contact_email_verification": false,
|
|
101
|
-
"official_contact_email_verification_token": "imperial_token_6",
|
|
102
|
-
"official_contact_email_verification_sent_at": "2023-07-06T00:00:00.000Z"
|
|
93
|
+
"has_been_greeted": true
|
|
103
94
|
}
|
|
104
95
|
]
|
|
105
96
|
`;
|
|
@@ -14,20 +14,16 @@ export function findByUserIdFactory({ pg }: DatabaseContext) {
|
|
|
14
14
|
const { rows }: QueryResult<Organization & BaseUserOrganizationLink> =
|
|
15
15
|
await pg.query(
|
|
16
16
|
`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
uo.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
INNER JOIN users_organizations uo ON uo.organization_id = o.id
|
|
28
|
-
WHERE uo.user_id = $1
|
|
29
|
-
ORDER BY o.created_at
|
|
30
|
-
`,
|
|
17
|
+
SELECT o.*,
|
|
18
|
+
uo.is_external,
|
|
19
|
+
uo.verification_type,
|
|
20
|
+
uo.verified_at,
|
|
21
|
+
uo.has_been_greeted
|
|
22
|
+
FROM organizations o
|
|
23
|
+
INNER JOIN users_organizations uo ON uo.organization_id = o.id
|
|
24
|
+
WHERE uo.user_id = $1
|
|
25
|
+
ORDER BY o.created_at
|
|
26
|
+
`,
|
|
31
27
|
[userId],
|
|
32
28
|
);
|
|
33
29
|
|
package/src/repositories/organization/{find-by-id.test.ts → find-organization-by-id.test.ts}
RENAMED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findOrganizationByIdFactory } from "./find-organization-by-id.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const findOrganizationById = findOrganizationByIdFactory({ pg: pg as any });
|
|
11
11
|
|
|
12
|
-
suite("
|
|
12
|
+
suite("findOrganizationByIdFactory", () => {
|
|
13
13
|
before(migrate);
|
|
14
14
|
beforeEach(emptyDatabase);
|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ suite("findByIdFactory", () => {
|
|
|
21
21
|
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
22
22
|
;
|
|
23
23
|
`;
|
|
24
|
-
const organization = await
|
|
24
|
+
const organization = await findOrganizationById(1);
|
|
25
25
|
|
|
26
26
|
assert.deepEqual(organization, {
|
|
27
27
|
cached_activite_principale: null,
|
|
@@ -5,8 +5,8 @@ import type { QueryResult } from "pg";
|
|
|
5
5
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
export function
|
|
9
|
-
return async function
|
|
8
|
+
export function findOrganizationByIdFactory({ pg }: DatabaseContext) {
|
|
9
|
+
return async function findOrganizationById(id: number) {
|
|
10
10
|
const { rows }: QueryResult<Organization> = await pg.query(
|
|
11
11
|
`
|
|
12
12
|
SELECT *
|
|
@@ -19,4 +19,4 @@ export function findByIdFactory({ pg }: DatabaseContext) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type FindByIdHandler = ReturnType<typeof
|
|
22
|
+
export type FindByIdHandler = ReturnType<typeof findOrganizationByIdFactory>;
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findUsersByOrganizationFactory } from "./find-users-by-organization.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const findUsersByOrganization = findUsersByOrganizationFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
11
13
|
|
|
12
|
-
describe("
|
|
14
|
+
describe("findUsersByOrganizationFactory", () => {
|
|
13
15
|
before(migrate);
|
|
14
16
|
beforeEach(emptyDatabase);
|
|
15
17
|
|
|
@@ -32,19 +34,18 @@ describe("getUsersByOrganizationFactory", () => {
|
|
|
32
34
|
|
|
33
35
|
await pg.sql`
|
|
34
36
|
INSERT INTO users_organizations
|
|
35
|
-
|
|
36
|
-
VALUES
|
|
37
|
-
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available', false, null, null)
|
|
37
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
38
|
+
VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available')
|
|
38
39
|
;
|
|
39
40
|
`;
|
|
40
41
|
|
|
41
|
-
const user = await
|
|
42
|
+
const user = await findUsersByOrganization(1);
|
|
42
43
|
|
|
43
44
|
t.assert.snapshot(user);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
it("❎ fail to find users for unknown organization id", async () => {
|
|
47
|
-
const user = await
|
|
48
|
+
const user = await findUsersByOrganization(42);
|
|
48
49
|
assert.deepEqual(user, []);
|
|
49
50
|
});
|
|
50
51
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
exports[`
|
|
1
|
+
exports[`findUsersByOrganizationFactory > should find users by organization id 1`] = `
|
|
2
2
|
[
|
|
3
3
|
{
|
|
4
4
|
"id": 1,
|
|
@@ -29,10 +29,7 @@ exports[`getUsersByOrganizationFactory > should find users by organization id 1`
|
|
|
29
29
|
"is_external": false,
|
|
30
30
|
"verification_type": "no_verification_means_available",
|
|
31
31
|
"verified_at": null,
|
|
32
|
-
"has_been_greeted": false
|
|
33
|
-
"needs_official_contact_email_verification": false,
|
|
34
|
-
"official_contact_email_verification_token": null,
|
|
35
|
-
"official_contact_email_verification_sent_at": null
|
|
32
|
+
"has_been_greeted": false
|
|
36
33
|
}
|
|
37
34
|
]
|
|
38
35
|
`;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
BaseUserOrganizationLink,
|
|
5
|
+
DatabaseContext,
|
|
6
|
+
User,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import type { QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
|
|
13
|
+
return async function findUsersByOrganization(
|
|
14
|
+
organization_id: number,
|
|
15
|
+
additionalWhereClause: string = "",
|
|
16
|
+
additionalParams: any[] = [],
|
|
17
|
+
) {
|
|
18
|
+
const connection = pg;
|
|
19
|
+
const baseParams = [organization_id];
|
|
20
|
+
|
|
21
|
+
const { rows }: QueryResult<User & BaseUserOrganizationLink> =
|
|
22
|
+
await connection.query(
|
|
23
|
+
`
|
|
24
|
+
SELECT u.*,
|
|
25
|
+
uo.is_external,
|
|
26
|
+
uo.verification_type,
|
|
27
|
+
uo.verified_at,
|
|
28
|
+
uo.has_been_greeted
|
|
29
|
+
FROM users u
|
|
30
|
+
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
31
|
+
WHERE uo.organization_id = $1
|
|
32
|
+
${additionalWhereClause}`,
|
|
33
|
+
[...baseParams, ...additionalParams],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return rows;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import { OrganizationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
7
|
+
import { getOrganizationByIdFactory } from "./get-organization-by-id.js";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
const getOrganizationById = getOrganizationByIdFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("getOrganizationByIdFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should throw OrganizationNotFoundError when not found", async () => {
|
|
18
|
+
await assert.rejects(
|
|
19
|
+
() => getOrganizationById(1),
|
|
20
|
+
(err: unknown) => err instanceof OrganizationNotFoundError,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("should return the organization when it exists", async () => {
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO organizations
|
|
27
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
28
|
+
VALUES
|
|
29
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const Organization = await getOrganizationById(1);
|
|
34
|
+
|
|
35
|
+
assert.equal(Organization.id, 1);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { type DatabaseContext, type Organization } from "#src/types";
|
|
4
|
+
import { OrganizationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
|
+
import { findOrganizationByIdFactory } from "./find-organization-by-id.js";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
export function getOrganizationByIdFactory({ pg }: DatabaseContext) {
|
|
10
|
+
const findOrganizationById = findOrganizationByIdFactory({ pg });
|
|
11
|
+
|
|
12
|
+
return async function getOrganizationById(id: number): Promise<Organization> {
|
|
13
|
+
const organization = await findOrganizationById(id);
|
|
14
|
+
if (!organization) {
|
|
15
|
+
throw new OrganizationNotFoundError(`Organization ${id} not found`);
|
|
16
|
+
}
|
|
17
|
+
return organization;
|
|
18
|
+
};
|
|
19
|
+
}
|