@proconnect-gouv/proconnect.identite.runtime 0.3.1 → 0.5.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 (101) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/activity/activity-context-schemas.d.ts +104 -0
  3. package/dist/activity/activity-context-schemas.d.ts.map +1 -1
  4. package/dist/activity/activity-context-schemas.js +6 -0
  5. package/dist/activity/types.d.ts +3 -0
  6. package/dist/activity/types.d.ts.map +1 -1
  7. package/dist/franceconnect/activities.d.ts +16 -0
  8. package/dist/franceconnect/activities.d.ts.map +1 -0
  9. package/dist/franceconnect/activities.js +17 -0
  10. package/dist/franceconnect/connect-franceconnect.d.ts +20 -0
  11. package/dist/franceconnect/connect-franceconnect.d.ts.map +1 -0
  12. package/dist/franceconnect/connect-franceconnect.js +59 -0
  13. package/dist/franceconnect/disconnect-franceconnect.d.ts +14 -0
  14. package/dist/franceconnect/disconnect-franceconnect.d.ts.map +1 -0
  15. package/dist/franceconnect/disconnect-franceconnect.js +29 -0
  16. package/dist/franceconnect/index.d.ts +4 -0
  17. package/dist/franceconnect/index.d.ts.map +1 -0
  18. package/dist/franceconnect/index.js +4 -0
  19. package/dist/journal/insert-activity.js +6 -0
  20. package/dist/memberships/activities.d.ts +27 -0
  21. package/dist/memberships/activities.d.ts.map +1 -1
  22. package/dist/memberships/activities.js +27 -0
  23. package/dist/memberships/add-membership.d.ts +22 -0
  24. package/dist/memberships/add-membership.d.ts.map +1 -0
  25. package/dist/memberships/add-membership.js +46 -0
  26. package/dist/memberships/index.d.ts +3 -0
  27. package/dist/memberships/index.d.ts.map +1 -1
  28. package/dist/memberships/index.js +3 -0
  29. package/dist/memberships/remove-membership.d.ts +19 -0
  30. package/dist/memberships/remove-membership.d.ts.map +1 -0
  31. package/dist/memberships/remove-membership.js +29 -0
  32. package/dist/memberships/update-membership.d.ts +31 -0
  33. package/dist/memberships/update-membership.d.ts.map +1 -0
  34. package/dist/memberships/update-membership.js +61 -0
  35. package/dist/moderations/activities.d.ts +11 -0
  36. package/dist/moderations/activities.d.ts.map +1 -0
  37. package/dist/moderations/activities.js +12 -0
  38. package/dist/moderations/index.d.ts +3 -0
  39. package/dist/moderations/index.d.ts.map +1 -0
  40. package/dist/moderations/index.js +3 -0
  41. package/dist/moderations/open-moderation.d.ts +18 -0
  42. package/dist/moderations/open-moderation.d.ts.map +1 -0
  43. package/dist/moderations/open-moderation.js +31 -0
  44. package/dist/runtime/create-identite-runtime.d.ts +152 -0
  45. package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
  46. package/dist/runtime/create-identite-runtime.js +22 -0
  47. package/dist/users/activities.d.ts +62 -0
  48. package/dist/users/activities.d.ts.map +1 -0
  49. package/dist/users/activities.js +54 -0
  50. package/dist/users/change-password.d.ts +16 -0
  51. package/dist/users/change-password.d.ts.map +1 -0
  52. package/dist/users/change-password.js +38 -0
  53. package/dist/users/delete-user.d.ts +14 -0
  54. package/dist/users/delete-user.d.ts.map +1 -0
  55. package/dist/users/delete-user.js +39 -0
  56. package/dist/users/index.d.ts +6 -0
  57. package/dist/users/index.d.ts.map +1 -0
  58. package/dist/users/index.js +6 -0
  59. package/dist/users/reset-mfa.d.ts +14 -0
  60. package/dist/users/reset-mfa.d.ts.map +1 -0
  61. package/dist/users/reset-mfa.js +53 -0
  62. package/dist/users/update-personal-informations.d.ts +21 -0
  63. package/dist/users/update-personal-informations.d.ts.map +1 -0
  64. package/dist/users/update-personal-informations.js +53 -0
  65. package/package.json +5 -4
  66. package/src/activity/activity-context-schemas.ts +6 -0
  67. package/src/activity/types.ts +2 -1
  68. package/src/domains/mark-domain-as-verified.test.ts +162 -243
  69. package/src/franceconnect/activities.ts +20 -0
  70. package/src/franceconnect/connect-franceconnect.test.ts +197 -0
  71. package/src/franceconnect/connect-franceconnect.ts +96 -0
  72. package/src/franceconnect/disconnect-franceconnect.test.ts +94 -0
  73. package/src/franceconnect/disconnect-franceconnect.ts +53 -0
  74. package/src/franceconnect/index.ts +5 -0
  75. package/src/journal/insert-activity.ts +6 -0
  76. package/src/memberships/activities.ts +27 -0
  77. package/src/memberships/add-membership.test.ts +129 -0
  78. package/src/memberships/add-membership.ts +80 -0
  79. package/src/memberships/index.ts +3 -0
  80. package/src/memberships/remove-membership.test.ts +122 -0
  81. package/src/memberships/remove-membership.ts +59 -0
  82. package/src/memberships/update-membership.test.ts +202 -0
  83. package/src/memberships/update-membership.ts +106 -0
  84. package/src/moderations/activities.ts +15 -0
  85. package/src/moderations/index.ts +4 -0
  86. package/src/moderations/open-moderation.test.ts +99 -0
  87. package/src/moderations/open-moderation.ts +59 -0
  88. package/src/runtime/create-identite-runtime.test.ts +20 -51
  89. package/src/runtime/create-identite-runtime.ts +34 -0
  90. package/src/users/activities.ts +60 -0
  91. package/src/users/change-password.test.ts +91 -0
  92. package/src/users/change-password.ts +64 -0
  93. package/src/users/delete-user.test.ts +142 -0
  94. package/src/users/delete-user.ts +60 -0
  95. package/src/users/index.ts +7 -0
  96. package/src/users/reset-mfa.test.ts +128 -0
  97. package/src/users/reset-mfa.ts +79 -0
  98. package/src/users/update-personal-informations.test.ts +113 -0
  99. package/src/users/update-personal-informations.ts +97 -0
  100. package/testing/index.ts +25 -0
  101. package/tsconfig.json +1 -1
@@ -1,66 +1,104 @@
1
1
  //
2
2
 
3
- import type { RuntimeContext } from "#src/activity";
3
+ import type { IdentiteDatabase } from "#src/database";
4
4
  import { createIdentiteRuntime } from "#src/runtime";
5
- import { PGlite } from "@electric-sql/pglite";
5
+ import { createTestDatabase, readActivityLogs } from "#testing";
6
6
  import * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
7
- import { migrate } from "@proconnect-gouv/proconnect.identite.database/pglite/migrator";
8
- import { drizzle } from "drizzle-orm/pglite";
7
+ import { sql } from "drizzle-orm";
9
8
  import assert from "node:assert/strict";
10
9
  import { before, describe, it, mock } from "node:test";
11
10
 
12
11
  //
13
12
 
14
- const join_official_contact = {
15
- actor: { type: "app", job: "join.official_contact" },
16
- app: "proconnect-identite",
17
- } satisfies Pick<RuntimeContext, "actor" | "app">;
18
-
19
- async function setup({ actor, app }: Pick<RuntimeContext, "actor" | "app">) {
20
- const pg = new PGlite();
21
- await migrate(pg);
22
-
23
- await pg.exec(`
24
- SET search_path TO public;
25
-
26
- INSERT INTO organizations
27
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
28
- VALUES
29
- (1, 'Dark Angels', 'Organization verifying darkangels.world', '🦁', '4444-04-04', '4444-04-04'),
30
- (2, 'Space Wolves', 'Other organization using darkangels.world', '🐺', '4444-04-04', '4444-04-04');
31
-
32
- INSERT INTO users
33
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
34
- VALUES
35
- (1, 'lion.eljonson+promoted@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque'),
36
- (2, 'azrael+promoted@darkangels.world', '4444-04-04', '4444-04-04', 'Azrael', 'Supreme', '0', 'Grand Master'),
37
- (3, 'luther+kept-dirigeant@darkangels.world', '4444-04-04', '4444-04-04', 'Luther', 'Fallen', '0', 'Second'),
38
- (4, 'leman.russ+kept-other-domain@spacewolves.world', '4444-04-04', '4444-04-04', 'Leman', 'Russ', '0', 'Primarque');
39
-
40
- INSERT INTO users_organizations
41
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
42
- VALUES
43
- (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
44
- (2, 1, '4444-04-04', '4444-04-04', false, 'domain_not_verified_yet'),
45
- (3, 1, '4444-04-04', '4444-04-04', false, 'organization_dirigeant'),
46
- (4, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available'),
47
- (1, 2, '4444-04-04', '4444-04-04', false, 'no_validation_means_available');
48
-
49
- INSERT INTO email_domains
50
- (id, organization_id, domain, verification_type, created_at, updated_at)
51
- VALUES
52
- (1, 1, 'darkangels.world', 'not_verified_yet', '4444-04-04', '4444-04-04'),
53
- (2, 1, 'darkangels.world', 'refused', '4444-04-04', '4444-04-04'),
54
- (3, 1, 'calibanites.world', 'verified', '4444-04-04', '4444-04-04'),
55
- (4, 2, 'darkangels.world', 'not_verified_yet', '4444-04-04', '4444-04-04');
56
- `);
13
+ async function setup() {
14
+ const db = await createTestDatabase();
15
+ await db.insert(schema.organizations).values([
16
+ { id: 1, siret: "🦁" },
17
+ { id: 2, siret: "🐺" },
18
+ ]);
19
+ await db.insert(schema.users).values(
20
+ [
21
+ "lion.eljonson+promoted@darkangels.world",
22
+ "azrael+promoted@darkangels.world",
23
+ "luther+kept-dirigeant@darkangels.world",
24
+ "leman.russ+kept-other-domain@spacewolves.world",
25
+ ].map((email, index) => ({
26
+ created_at: "4444-04-04",
27
+ email,
28
+ id: index + 1,
29
+ updated_at: "4444-04-04",
30
+ })),
31
+ );
32
+ await db.insert(schema.users_organizations).values(
33
+ [
34
+ {
35
+ organization_id: 1,
36
+ user_id: 1,
37
+ verification_type:
38
+ "no_verification_means_for_entreprise_unipersonnelle",
39
+ },
40
+ {
41
+ organization_id: 1,
42
+ user_id: 2,
43
+ verification_type: "domain_not_verified_yet",
44
+ },
45
+ {
46
+ organization_id: 1,
47
+ user_id: 3,
48
+ verification_type: "organization_dirigeant",
49
+ },
50
+ {
51
+ organization_id: 1,
52
+ user_id: 4,
53
+ verification_type: "no_validation_means_available",
54
+ },
55
+ {
56
+ organization_id: 2,
57
+ user_id: 1,
58
+ verification_type: "no_validation_means_available",
59
+ },
60
+ ].map((membership) => ({
61
+ ...membership,
62
+ created_at: "4444-04-04",
63
+ updated_at: "4444-04-04",
64
+ })),
65
+ );
66
+ await db.insert(schema.email_domains).values(
67
+ [
68
+ {
69
+ domain: "darkangels.world",
70
+ organization_id: 1,
71
+ verification_type: "not_verified_yet",
72
+ },
73
+ {
74
+ domain: "darkangels.world",
75
+ organization_id: 1,
76
+ verification_type: "refused",
77
+ },
78
+ {
79
+ domain: "calibanites.world",
80
+ organization_id: 1,
81
+ verification_type: "verified",
82
+ },
83
+ {
84
+ domain: "darkangels.world",
85
+ organization_id: 2,
86
+ verification_type: "not_verified_yet",
87
+ },
88
+ ].map((email_domain, index) => ({
89
+ ...email_domain,
90
+ created_at: "4444-04-04",
91
+ id: index + 1,
92
+ updated_at: "4444-04-04",
93
+ })),
94
+ );
57
95
 
58
96
  return {
59
- pg,
60
- runtime: createIdentiteRuntime({
61
- app,
62
- db: drizzle(pg, { schema }),
63
- }).as(actor),
97
+ db,
98
+ runtime: createIdentiteRuntime({ app: "hyyypertool", db }).as({
99
+ type: "moderator",
100
+ sub: "moderator+verifies-darkangels.world",
101
+ }),
64
102
  };
65
103
  }
66
104
 
@@ -70,12 +108,12 @@ describe("markDomainAsVerified", () => {
70
108
  });
71
109
 
72
110
  it("❎ returns organization_not_found for an unknown organization", async () => {
73
- const { pg, runtime } = await setup(join_official_contact);
74
- const before = await snapshot(pg);
111
+ const { db, runtime } = await setup();
112
+ const before = await snapshot(db);
75
113
 
76
114
  const outcome = await runtime.markDomainAsVerified({
77
115
  domain: "notfound.world",
78
- domain_verification_type: "official_contact",
116
+ domain_verification_type: "verified",
79
117
  organization_id: 404,
80
118
  });
81
119
 
@@ -83,30 +121,30 @@ describe("markDomainAsVerified", () => {
83
121
  kind: "organization_not_found",
84
122
  organization_id: 404,
85
123
  });
86
- assert.deepEqual(await snapshot(pg), before);
87
- assert.deepEqual(await readActivityLogs(pg), []);
124
+ assert.deepEqual(await snapshot(db), before);
125
+ assert.deepEqual(await readActivityLogs(db), []);
88
126
  });
89
127
 
90
- it("✅ replaces the domain states, promotes the domain members and journals the verification and each promotion", async () => {
91
- const { pg, runtime } = await setup(join_official_contact);
128
+ it("✅ replaces the domain states, promotes the domain members and journals the verification under the moderator and each promotion under the app", async () => {
129
+ const { db, runtime } = await setup();
92
130
 
93
131
  const outcome = await runtime.markDomainAsVerified({
94
132
  domain: "darkangels.world",
95
- domain_verification_type: "official_contact",
133
+ domain_verification_type: "verified",
96
134
  organization_id: 1,
97
135
  });
98
136
 
99
- const {
100
- rows: [official_contact_domain],
101
- } = await pg.query<{ id: number }>(
102
- "SELECT id FROM email_domains WHERE verification_type = 'official_contact'",
103
- );
137
+ const verified_domain = await db.query.email_domains.findFirst({
138
+ columns: { id: true },
139
+ where: (table, { and, eq }) =>
140
+ and(eq(table.domain, "darkangels.world"), eq(table.organization_id, 1)),
141
+ });
104
142
  assert.deepEqual(outcome, {
105
143
  kind: "domain_verified",
106
144
  activity_id: 1,
107
145
  email_domain: {
108
- id: official_contact_domain?.id,
109
- verification_type: "official_contact",
146
+ id: verified_domain?.id,
147
+ verification_type: "verified",
110
148
  },
111
149
  promoted_members: [
112
150
  {
@@ -119,23 +157,25 @@ describe("markDomainAsVerified", () => {
119
157
  replaced_verification_types: ["not_verified_yet", "refused"],
120
158
  });
121
159
  assert.deepEqual(
122
- (
123
- await pg.query(`
124
- SELECT
125
- organization_id,
126
- domain,
127
- verification_type,
128
- can_be_suggested,
129
- created_at,
130
- verified_at
131
- FROM email_domains
132
- ORDER BY organization_id, domain, verification_type
133
- `)
134
- ).rows,
160
+ await db.query.email_domains.findMany({
161
+ columns: {
162
+ can_be_suggested: true,
163
+ created_at: true,
164
+ domain: true,
165
+ organization_id: true,
166
+ verification_type: true,
167
+ verified_at: true,
168
+ },
169
+ orderBy: (table, { asc }) => [
170
+ asc(table.organization_id),
171
+ asc(table.domain),
172
+ asc(table.verification_type),
173
+ ],
174
+ }),
135
175
  [
136
176
  {
137
177
  can_be_suggested: true,
138
- created_at: new Date("4444-04-04"),
178
+ created_at: "4444-04-04 00:00:00+00",
139
179
  domain: "calibanites.world",
140
180
  organization_id: 1,
141
181
  verification_type: "verified",
@@ -143,15 +183,15 @@ describe("markDomainAsVerified", () => {
143
183
  },
144
184
  {
145
185
  can_be_suggested: true,
146
- created_at: new Date("5555-05-05"),
186
+ created_at: "5555-05-05 00:00:00+00",
147
187
  domain: "darkangels.world",
148
188
  organization_id: 1,
149
- verification_type: "official_contact",
150
- verified_at: new Date("5555-05-05"),
189
+ verification_type: "verified",
190
+ verified_at: "5555-05-05 00:00:00+00",
151
191
  },
152
192
  {
153
193
  can_be_suggested: true,
154
- created_at: new Date("4444-04-04"),
194
+ created_at: "4444-04-04 00:00:00+00",
155
195
  domain: "darkangels.world",
156
196
  organization_id: 2,
157
197
  verification_type: "not_verified_yet",
@@ -160,149 +200,52 @@ describe("markDomainAsVerified", () => {
160
200
  ],
161
201
  );
162
202
  assert.deepEqual(
163
- (
164
- await pg.query(`
165
- SELECT
166
- organization_id,
167
- user_id,
168
- verification_type,
169
- updated_at
170
- FROM users_organizations
171
- ORDER BY organization_id, user_id
172
- `)
173
- ).rows,
203
+ await db.query.users_organizations.findMany({
204
+ columns: {
205
+ organization_id: true,
206
+ updated_at: true,
207
+ user_id: true,
208
+ verification_type: true,
209
+ },
210
+ orderBy: (table, { asc }) => [
211
+ asc(table.organization_id),
212
+ asc(table.user_id),
213
+ ],
214
+ }),
174
215
  [
175
216
  {
176
217
  organization_id: 1,
177
- updated_at: new Date("5555-05-05"),
218
+ updated_at: "5555-05-05 00:00:00+00",
178
219
  user_id: 1,
179
220
  verification_type: "domain",
180
221
  },
181
222
  {
182
223
  organization_id: 1,
183
- updated_at: new Date("5555-05-05"),
224
+ updated_at: "5555-05-05 00:00:00+00",
184
225
  user_id: 2,
185
226
  verification_type: "domain",
186
227
  },
187
228
  {
188
229
  organization_id: 1,
189
- updated_at: new Date("4444-04-04"),
230
+ updated_at: "4444-04-04 00:00:00+00",
190
231
  user_id: 3,
191
232
  verification_type: "organization_dirigeant",
192
233
  },
193
234
  {
194
235
  organization_id: 1,
195
- updated_at: new Date("4444-04-04"),
236
+ updated_at: "4444-04-04 00:00:00+00",
196
237
  user_id: 4,
197
238
  verification_type: "no_validation_means_available",
198
239
  },
199
240
  {
200
241
  organization_id: 2,
201
- updated_at: new Date("4444-04-04"),
242
+ updated_at: "4444-04-04 00:00:00+00",
202
243
  user_id: 1,
203
244
  verification_type: "no_validation_means_available",
204
245
  },
205
246
  ],
206
247
  );
207
- assert.deepEqual(await readActivityLogs(pg), [
208
- {
209
- action: "domain.verified",
210
- actor_ref: "join.official_contact",
211
- actor_type: "app",
212
- app: "proconnect-identite",
213
- cause_activity_id: null,
214
- context: {
215
- inputs: {
216
- domain: "darkangels.world",
217
- verification_type: "official_contact",
218
- },
219
- outcome: {
220
- email_domain_id: official_contact_domain?.id,
221
- replaced_verification_types: ["not_verified_yet", "refused"],
222
- },
223
- },
224
- created_at: new Date("5555-05-05"),
225
- id: 1,
226
- interaction_cid: null,
227
- moderation_id: null,
228
- organization_id: 1,
229
- user_id: null,
230
- },
231
- {
232
- action: "member.promoted",
233
- actor_ref: "domain.promote_members",
234
- actor_type: "app",
235
- app: "proconnect-identite",
236
- cause_activity_id: 1,
237
- context: {
238
- inputs: {
239
- previous_verification_type:
240
- "no_verification_means_for_entreprise_unipersonnelle",
241
- },
242
- outcome: { verification_type: "domain" },
243
- },
244
- created_at: new Date("5555-05-05"),
245
- id: 2,
246
- interaction_cid: null,
247
- moderation_id: null,
248
- organization_id: 1,
249
- user_id: 1,
250
- },
251
- {
252
- action: "member.promoted",
253
- actor_ref: "domain.promote_members",
254
- actor_type: "app",
255
- app: "proconnect-identite",
256
- cause_activity_id: 1,
257
- context: {
258
- inputs: { previous_verification_type: "domain_not_verified_yet" },
259
- outcome: { verification_type: "domain" },
260
- },
261
- created_at: new Date("5555-05-05"),
262
- id: 3,
263
- interaction_cid: null,
264
- moderation_id: null,
265
- organization_id: 1,
266
- user_id: 2,
267
- },
268
- ]);
269
- });
270
-
271
- it("✅ journals the verification under the moderator and each promotion under the app", async () => {
272
- const { pg, runtime } = await setup({
273
- actor: { type: "moderator", sub: "moderator+verifies-darkangels.world" },
274
- app: "hyyypertool",
275
- });
276
-
277
- const outcome = await runtime.markDomainAsVerified({
278
- domain: "darkangels.world",
279
- domain_verification_type: "verified",
280
- organization_id: 1,
281
- });
282
-
283
- const {
284
- rows: [verified_domain],
285
- } = await pg.query<{ id: number }>(
286
- "SELECT id FROM email_domains WHERE domain = 'darkangels.world' AND verification_type = 'verified'",
287
- );
288
- assert.deepEqual(outcome, {
289
- kind: "domain_verified",
290
- activity_id: 1,
291
- email_domain: {
292
- id: verified_domain?.id,
293
- verification_type: "verified",
294
- },
295
- promoted_members: [
296
- {
297
- previous_verification_type:
298
- "no_verification_means_for_entreprise_unipersonnelle",
299
- user_id: 1,
300
- },
301
- { previous_verification_type: "domain_not_verified_yet", user_id: 2 },
302
- ],
303
- replaced_verification_types: ["not_verified_yet", "refused"],
304
- });
305
- assert.deepEqual(await readActivityLogs(pg), [
248
+ assert.deepEqual(await readActivityLogs(db), [
306
249
  {
307
250
  action: "domain.verified",
308
251
  actor_ref: "moderator+verifies-darkangels.world",
@@ -319,8 +262,6 @@ describe("markDomainAsVerified", () => {
319
262
  replaced_verification_types: ["not_verified_yet", "refused"],
320
263
  },
321
264
  },
322
- created_at: new Date("5555-05-05"),
323
- id: 1,
324
265
  interaction_cid: null,
325
266
  moderation_id: null,
326
267
  organization_id: 1,
@@ -339,8 +280,6 @@ describe("markDomainAsVerified", () => {
339
280
  },
340
281
  outcome: { verification_type: "domain" },
341
282
  },
342
- created_at: new Date("5555-05-05"),
343
- id: 2,
344
283
  interaction_cid: null,
345
284
  moderation_id: null,
346
285
  organization_id: 1,
@@ -356,8 +295,6 @@ describe("markDomainAsVerified", () => {
356
295
  inputs: { previous_verification_type: "domain_not_verified_yet" },
357
296
  outcome: { verification_type: "domain" },
358
297
  },
359
- created_at: new Date("5555-05-05"),
360
- id: 3,
361
298
  interaction_cid: null,
362
299
  moderation_id: null,
363
300
  organization_id: 1,
@@ -367,57 +304,39 @@ describe("markDomainAsVerified", () => {
367
304
  });
368
305
 
369
306
  it("❎ rolls back the domain state and its journal row when a member update fails", async () => {
370
- const { pg, runtime } = await setup(join_official_contact);
371
- await pg.exec(`
307
+ const { db, runtime } = await setup();
308
+ await db.execute(sql`
372
309
  ALTER TABLE users_organizations
373
310
  ADD CONSTRAINT users_organizations_never_domain
374
- CHECK (verification_type <> 'domain');
311
+ CHECK (verification_type <> 'domain')
375
312
  `);
376
- const before = await snapshot(pg);
313
+ const before = await snapshot(db);
377
314
 
378
315
  await assert.rejects(
379
316
  runtime.markDomainAsVerified({
380
317
  domain: "darkangels.world",
381
- domain_verification_type: "official_contact",
318
+ domain_verification_type: "verified",
382
319
  organization_id: 1,
383
320
  }),
384
321
  (error: Error) =>
385
322
  error.cause instanceof Error &&
386
323
  error.cause.message.includes("users_organizations_never_domain"),
387
324
  );
388
- assert.deepEqual(await snapshot(pg), before);
389
- assert.deepEqual(await readActivityLogs(pg), []);
325
+ assert.deepEqual(await snapshot(db), before);
326
+ assert.deepEqual(await readActivityLogs(db), []);
390
327
  });
391
328
  });
392
329
 
393
- async function snapshot(pg: PGlite) {
394
- const [{ rows: email_domains }, { rows: users_organizations }] =
395
- await Promise.all([
396
- pg.query("SELECT * FROM email_domains ORDER BY id"),
397
- pg.query(
398
- "SELECT * FROM users_organizations ORDER BY organization_id, user_id",
399
- ),
400
- ]);
401
- return { email_domains, users_organizations };
402
- }
403
-
404
- async function readActivityLogs(pg: PGlite) {
405
- const { rows } = await pg.query(`
406
- SELECT
407
- action,
408
- actor_ref,
409
- actor_type,
410
- app,
411
- cause_activity_id,
412
- context,
413
- created_at,
414
- id,
415
- interaction_cid,
416
- moderation_id,
417
- organization_id,
418
- user_id
419
- FROM activity_logs
420
- ORDER BY id
421
- `);
422
- return rows;
330
+ async function snapshot(db: IdentiteDatabase) {
331
+ return {
332
+ email_domains: await db.query.email_domains.findMany({
333
+ orderBy: (table, { asc }) => asc(table.id),
334
+ }),
335
+ users_organizations: await db.query.users_organizations.findMany({
336
+ orderBy: (table, { asc }) => [
337
+ asc(table.organization_id),
338
+ asc(table.user_id),
339
+ ],
340
+ }),
341
+ };
423
342
  }
@@ -0,0 +1,20 @@
1
+ //
2
+
3
+ import * as z from "zod";
4
+
5
+ //
6
+
7
+ export const franceconnectActivities = {
8
+ "franceconnect.connected": z.object({
9
+ inputs: z.object({}),
10
+ outcome: z.object({
11
+ connected_at: z.string(),
12
+ }),
13
+ }),
14
+ "franceconnect.disconnected": z.object({
15
+ inputs: z.object({}),
16
+ outcome: z.object({
17
+ connected_at: z.string(),
18
+ }),
19
+ }),
20
+ };