@proconnect-gouv/proconnect.identite.runtime 0.1.0 → 0.3.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 +22 -0
- package/dist/activity/activity-context-schemas.d.ts +46 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -0
- package/dist/activity/activity-context-schemas.js +8 -0
- package/dist/activity/index.d.ts +3 -0
- package/dist/activity/index.d.ts.map +1 -0
- package/dist/activity/index.js +3 -0
- package/dist/activity/types.d.ts +36 -0
- package/dist/activity/types.d.ts.map +1 -0
- package/dist/activity/types.js +2 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +2 -0
- package/dist/domains/activities.d.ts +19 -0
- package/dist/domains/activities.d.ts.map +1 -0
- package/dist/domains/activities.js +16 -0
- package/dist/domains/index.d.ts +3 -0
- package/dist/domains/index.d.ts.map +1 -0
- package/dist/domains/index.js +3 -0
- package/dist/domains/mark-domain-as-verified.d.ts +25 -0
- package/dist/domains/mark-domain-as-verified.d.ts.map +1 -0
- package/dist/domains/mark-domain-as-verified.js +103 -0
- package/dist/index.d.ts +4 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -88
- package/dist/journal/index.d.ts +2 -0
- package/dist/journal/index.d.ts.map +1 -0
- package/dist/journal/index.js +2 -0
- package/dist/journal/insert-activity.d.ts +8 -0
- package/dist/journal/insert-activity.d.ts.map +1 -0
- package/dist/journal/insert-activity.js +22 -0
- package/dist/memberships/activities.d.ts +30 -0
- package/dist/memberships/activities.d.ts.map +1 -0
- package/dist/memberships/activities.js +14 -0
- package/dist/memberships/index.d.ts +2 -0
- package/dist/memberships/index.d.ts.map +1 -0
- package/dist/memberships/index.js +2 -0
- package/dist/runtime/create-identite-runtime.d.ts +32 -0
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -0
- package/dist/runtime/create-identite-runtime.js +14 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/package.json +11 -5
- package/src/activity/activity-context-schemas.ts +14 -0
- package/src/activity/index.ts +4 -0
- package/src/activity/types.ts +39 -0
- package/src/{database.ts → database/index.ts} +4 -0
- package/src/domains/activities.ts +19 -0
- package/src/domains/index.ts +4 -0
- package/src/domains/mark-domain-as-verified.test.ts +423 -0
- package/src/{mark-domain-as-verified.ts → domains/mark-domain-as-verified.ts} +54 -11
- package/src/index.ts +3 -12
- package/src/journal/index.ts +3 -0
- package/src/journal/insert-activity.ts +43 -0
- package/src/memberships/activities.ts +17 -0
- package/src/memberships/index.ts +3 -0
- package/src/runtime/create-identite-runtime.test.ts +148 -0
- package/src/runtime/create-identite-runtime.ts +33 -0
- package/src/runtime/index.ts +3 -0
- package/tsconfig.json +6 -3
- package/src/mark-domain-as-verified.test.ts +0 -226
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-identite-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/create-identite-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAMzD,wBAAgB,qBAAqB,CACnC,WAAW,SAAS,UAAU,GAAG;KAC9B,MAAM,IAAI,MAAM,gBAAgB,CAAC,CAAC,EAAE,KAAK;CAC3C,GAAG,EAAE,EACN,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;cAE9B,KAAK;;;;;;;;;;;;;;;;;;;;;qBAIL,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;EAK5D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { markDomainAsVerifiedFactory } from "#src/domains";
|
|
3
|
+
import { insertActivity } from "#src/journal";
|
|
4
|
+
//
|
|
5
|
+
export function createIdentiteRuntime({ app, db }) {
|
|
6
|
+
return {
|
|
7
|
+
as(actor) {
|
|
8
|
+
return {
|
|
9
|
+
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
10
|
+
record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAEA,cAAc,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite.runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/runtime#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"type": "module",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#src/*": {
|
|
16
|
+
"types": "./dist/*/index.d.ts",
|
|
17
|
+
"default": "./dist/*/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
14
20
|
"exports": {
|
|
15
21
|
".": {
|
|
16
22
|
"import": "./dist/index.js",
|
|
@@ -18,22 +24,22 @@
|
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
21
|
-
"build": "
|
|
27
|
+
"build": "tsc --build tsconfig.lib.json",
|
|
22
28
|
"check": "npm run build -- --noEmit",
|
|
23
29
|
"dev": "npm run build -- --watch --preserveWatchOutput",
|
|
24
30
|
"dev:test": "tsx --watch --test src/**/*.test.ts",
|
|
25
|
-
"test": "tsx --test --test-reporter=spec
|
|
31
|
+
"test": "tsc --noEmit && tsx --test --test-reporter=spec"
|
|
26
32
|
},
|
|
27
33
|
"dependencies": {
|
|
28
34
|
"@proconnect-gouv/proconnect.identite": "^12.0.0",
|
|
29
|
-
"@proconnect-gouv/proconnect.identite.database": "^1.
|
|
35
|
+
"@proconnect-gouv/proconnect.identite.database": "^1.12.0",
|
|
36
|
+
"zod": "^4.6.7"
|
|
30
37
|
},
|
|
31
38
|
"devDependencies": {
|
|
32
39
|
"@electric-sql/pglite": "^0.3.12",
|
|
33
40
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
34
41
|
"@types/node": "^22.18.6",
|
|
35
42
|
"drizzle-orm": "^0.45.4",
|
|
36
|
-
"pkgroll": "^2.22.0",
|
|
37
43
|
"tsx": "^4.20.3"
|
|
38
44
|
},
|
|
39
45
|
"peerDependencies": {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { domainActivities } from "#src/domains";
|
|
4
|
+
import { membershipActivities } from "#src/memberships";
|
|
5
|
+
import type { ContextsOf } from "./types.js";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
export const activityContextSchemas = {
|
|
10
|
+
...domainActivities,
|
|
11
|
+
...membershipActivities,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ActivityContexts = ContextsOf<typeof activityContextSchemas>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { IdentiteDatabase } from "#src/database";
|
|
4
|
+
import type * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export type Actor =
|
|
9
|
+
| { type: "app"; job: string }
|
|
10
|
+
| { type: "moderator"; sub: string };
|
|
11
|
+
|
|
12
|
+
export type App = "hyyypertool" | "proconnect-identite";
|
|
13
|
+
|
|
14
|
+
export type RuntimeContext = {
|
|
15
|
+
actor: Actor;
|
|
16
|
+
app: App;
|
|
17
|
+
db: IdentiteDatabase;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ContextShape = { inputs: unknown; outcome: unknown };
|
|
21
|
+
|
|
22
|
+
export type ContextMap = Record<string, ContextShape>;
|
|
23
|
+
|
|
24
|
+
export type ContextsOf<
|
|
25
|
+
Schemas extends Record<string, z.ZodType<ContextShape>>,
|
|
26
|
+
> = { [Action in keyof Schemas]: z.infer<Schemas[Action]> };
|
|
27
|
+
|
|
28
|
+
export type ActivityOf<Contexts extends ContextMap> = {
|
|
29
|
+
[Action in keyof Contexts & string]: {
|
|
30
|
+
action: Action;
|
|
31
|
+
context: Contexts[Action];
|
|
32
|
+
};
|
|
33
|
+
}[keyof Contexts & string];
|
|
34
|
+
|
|
35
|
+
export type ActivityTargets = {
|
|
36
|
+
moderation_id?: number;
|
|
37
|
+
organization_id?: number;
|
|
38
|
+
user_id?: number;
|
|
39
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { EmailDomainApprovedVerificationEnum } from "@proconnect-gouv/proconnect.identite/types";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export const domainActivities = {
|
|
9
|
+
"domain.verified": z.object({
|
|
10
|
+
inputs: z.object({
|
|
11
|
+
domain: z.string(),
|
|
12
|
+
verification_type: EmailDomainApprovedVerificationEnum,
|
|
13
|
+
}),
|
|
14
|
+
outcome: z.object({
|
|
15
|
+
email_domain_id: z.number(),
|
|
16
|
+
replaced_verification_types: z.array(z.string()),
|
|
17
|
+
}),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { RuntimeContext } from "#src/activity";
|
|
4
|
+
import { createIdentiteRuntime } from "#src/runtime";
|
|
5
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
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";
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
import { before, describe, it, mock } from "node:test";
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
|
|
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
|
+
`);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
pg,
|
|
60
|
+
runtime: createIdentiteRuntime({
|
|
61
|
+
app,
|
|
62
|
+
db: drizzle(pg, { schema }),
|
|
63
|
+
}).as(actor),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe("markDomainAsVerified", () => {
|
|
68
|
+
before(() => {
|
|
69
|
+
mock.timers.enable({ apis: ["Date"], now: new Date("5555-05-05") });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
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);
|
|
75
|
+
|
|
76
|
+
const outcome = await runtime.markDomainAsVerified({
|
|
77
|
+
domain: "notfound.world",
|
|
78
|
+
domain_verification_type: "official_contact",
|
|
79
|
+
organization_id: 404,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
assert.deepEqual(outcome, {
|
|
83
|
+
kind: "organization_not_found",
|
|
84
|
+
organization_id: 404,
|
|
85
|
+
});
|
|
86
|
+
assert.deepEqual(await snapshot(pg), before);
|
|
87
|
+
assert.deepEqual(await readActivityLogs(pg), []);
|
|
88
|
+
});
|
|
89
|
+
|
|
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);
|
|
92
|
+
|
|
93
|
+
const outcome = await runtime.markDomainAsVerified({
|
|
94
|
+
domain: "darkangels.world",
|
|
95
|
+
domain_verification_type: "official_contact",
|
|
96
|
+
organization_id: 1,
|
|
97
|
+
});
|
|
98
|
+
|
|
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
|
+
);
|
|
104
|
+
assert.deepEqual(outcome, {
|
|
105
|
+
kind: "domain_verified",
|
|
106
|
+
activity_id: 1,
|
|
107
|
+
email_domain: {
|
|
108
|
+
id: official_contact_domain?.id,
|
|
109
|
+
verification_type: "official_contact",
|
|
110
|
+
},
|
|
111
|
+
promoted_members: [
|
|
112
|
+
{
|
|
113
|
+
previous_verification_type:
|
|
114
|
+
"no_verification_means_for_entreprise_unipersonnelle",
|
|
115
|
+
user_id: 1,
|
|
116
|
+
},
|
|
117
|
+
{ previous_verification_type: "domain_not_verified_yet", user_id: 2 },
|
|
118
|
+
],
|
|
119
|
+
replaced_verification_types: ["not_verified_yet", "refused"],
|
|
120
|
+
});
|
|
121
|
+
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,
|
|
135
|
+
[
|
|
136
|
+
{
|
|
137
|
+
can_be_suggested: true,
|
|
138
|
+
created_at: new Date("4444-04-04"),
|
|
139
|
+
domain: "calibanites.world",
|
|
140
|
+
organization_id: 1,
|
|
141
|
+
verification_type: "verified",
|
|
142
|
+
verified_at: null,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
can_be_suggested: true,
|
|
146
|
+
created_at: new Date("5555-05-05"),
|
|
147
|
+
domain: "darkangels.world",
|
|
148
|
+
organization_id: 1,
|
|
149
|
+
verification_type: "official_contact",
|
|
150
|
+
verified_at: new Date("5555-05-05"),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
can_be_suggested: true,
|
|
154
|
+
created_at: new Date("4444-04-04"),
|
|
155
|
+
domain: "darkangels.world",
|
|
156
|
+
organization_id: 2,
|
|
157
|
+
verification_type: "not_verified_yet",
|
|
158
|
+
verified_at: null,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
);
|
|
162
|
+
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,
|
|
174
|
+
[
|
|
175
|
+
{
|
|
176
|
+
organization_id: 1,
|
|
177
|
+
updated_at: new Date("5555-05-05"),
|
|
178
|
+
user_id: 1,
|
|
179
|
+
verification_type: "domain",
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
organization_id: 1,
|
|
183
|
+
updated_at: new Date("5555-05-05"),
|
|
184
|
+
user_id: 2,
|
|
185
|
+
verification_type: "domain",
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
organization_id: 1,
|
|
189
|
+
updated_at: new Date("4444-04-04"),
|
|
190
|
+
user_id: 3,
|
|
191
|
+
verification_type: "organization_dirigeant",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
organization_id: 1,
|
|
195
|
+
updated_at: new Date("4444-04-04"),
|
|
196
|
+
user_id: 4,
|
|
197
|
+
verification_type: "no_validation_means_available",
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
organization_id: 2,
|
|
201
|
+
updated_at: new Date("4444-04-04"),
|
|
202
|
+
user_id: 1,
|
|
203
|
+
verification_type: "no_validation_means_available",
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
);
|
|
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), [
|
|
306
|
+
{
|
|
307
|
+
action: "domain.verified",
|
|
308
|
+
actor_ref: "moderator+verifies-darkangels.world",
|
|
309
|
+
actor_type: "moderator",
|
|
310
|
+
app: "hyyypertool",
|
|
311
|
+
cause_activity_id: null,
|
|
312
|
+
context: {
|
|
313
|
+
inputs: {
|
|
314
|
+
domain: "darkangels.world",
|
|
315
|
+
verification_type: "verified",
|
|
316
|
+
},
|
|
317
|
+
outcome: {
|
|
318
|
+
email_domain_id: verified_domain?.id,
|
|
319
|
+
replaced_verification_types: ["not_verified_yet", "refused"],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
created_at: new Date("5555-05-05"),
|
|
323
|
+
id: 1,
|
|
324
|
+
interaction_cid: null,
|
|
325
|
+
moderation_id: null,
|
|
326
|
+
organization_id: 1,
|
|
327
|
+
user_id: null,
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
action: "member.promoted",
|
|
331
|
+
actor_ref: "domain.promote_members",
|
|
332
|
+
actor_type: "app",
|
|
333
|
+
app: "hyyypertool",
|
|
334
|
+
cause_activity_id: 1,
|
|
335
|
+
context: {
|
|
336
|
+
inputs: {
|
|
337
|
+
previous_verification_type:
|
|
338
|
+
"no_verification_means_for_entreprise_unipersonnelle",
|
|
339
|
+
},
|
|
340
|
+
outcome: { verification_type: "domain" },
|
|
341
|
+
},
|
|
342
|
+
created_at: new Date("5555-05-05"),
|
|
343
|
+
id: 2,
|
|
344
|
+
interaction_cid: null,
|
|
345
|
+
moderation_id: null,
|
|
346
|
+
organization_id: 1,
|
|
347
|
+
user_id: 1,
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
action: "member.promoted",
|
|
351
|
+
actor_ref: "domain.promote_members",
|
|
352
|
+
actor_type: "app",
|
|
353
|
+
app: "hyyypertool",
|
|
354
|
+
cause_activity_id: 1,
|
|
355
|
+
context: {
|
|
356
|
+
inputs: { previous_verification_type: "domain_not_verified_yet" },
|
|
357
|
+
outcome: { verification_type: "domain" },
|
|
358
|
+
},
|
|
359
|
+
created_at: new Date("5555-05-05"),
|
|
360
|
+
id: 3,
|
|
361
|
+
interaction_cid: null,
|
|
362
|
+
moderation_id: null,
|
|
363
|
+
organization_id: 1,
|
|
364
|
+
user_id: 2,
|
|
365
|
+
},
|
|
366
|
+
]);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
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(`
|
|
372
|
+
ALTER TABLE users_organizations
|
|
373
|
+
ADD CONSTRAINT users_organizations_never_domain
|
|
374
|
+
CHECK (verification_type <> 'domain');
|
|
375
|
+
`);
|
|
376
|
+
const before = await snapshot(pg);
|
|
377
|
+
|
|
378
|
+
await assert.rejects(
|
|
379
|
+
runtime.markDomainAsVerified({
|
|
380
|
+
domain: "darkangels.world",
|
|
381
|
+
domain_verification_type: "official_contact",
|
|
382
|
+
organization_id: 1,
|
|
383
|
+
}),
|
|
384
|
+
(error: Error) =>
|
|
385
|
+
error.cause instanceof Error &&
|
|
386
|
+
error.cause.message.includes("users_organizations_never_domain"),
|
|
387
|
+
);
|
|
388
|
+
assert.deepEqual(await snapshot(pg), before);
|
|
389
|
+
assert.deepEqual(await readActivityLogs(pg), []);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
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;
|
|
423
|
+
}
|