@proconnect-gouv/proconnect.identite 13.0.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/connectors/index.d.ts +0 -56
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +4 -11
- package/dist/repositories/franceconnect_userinfo/index.d.ts +0 -2
- package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -1
- package/dist/repositories/franceconnect_userinfo/index.js +0 -2
- package/dist/repositories/moderation/index.d.ts +0 -1
- package/dist/repositories/moderation/index.d.ts.map +1 -1
- package/dist/repositories/moderation/index.js +0 -1
- package/dist/repositories/user/index.d.ts +0 -1
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -1
- package/dist/repositories/user_organisation/index.d.ts +0 -3
- package/dist/repositories/user_organisation/index.d.ts.map +1 -1
- package/dist/repositories/user_organisation/index.js +0 -3
- package/package.json +3 -3
- package/src/connectors/index.ts +1 -17
- package/src/repositories/franceconnect_userinfo/index.ts +0 -2
- package/src/repositories/moderation/index.ts +0 -1
- package/src/repositories/user/index.ts +0 -1
- package/src/repositories/user_organisation/index.ts +0 -3
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +0 -4
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.js +0 -10
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts +0 -16
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.js +0 -23
- package/dist/repositories/moderation/create-moderation.d.ts +0 -22
- package/dist/repositories/moderation/create-moderation.d.ts.map +0 -1
- package/dist/repositories/moderation/create-moderation.js +0 -21
- package/dist/repositories/user/delete.d.ts +0 -3
- package/dist/repositories/user/delete.d.ts.map +0 -1
- package/dist/repositories/user/delete.js +0 -11
- package/dist/repositories/user_organisation/create-user-organization.d.ts +0 -12
- package/dist/repositories/user_organisation/create-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/create-user-organization.js +0 -21
- package/dist/repositories/user_organisation/delete-user-organization.d.ts +0 -3
- package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/delete-user-organization.js +0 -12
- package/dist/repositories/user_organisation/update-user-organization.d.ts +0 -12
- package/dist/repositories/user_organisation/update-user-organization.d.ts.map +0 -1
- package/dist/repositories/user_organisation/update-user-organization.js +0 -20
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.test.ts +0 -47
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +0 -21
- package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.test.ts +0 -102
- package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.ts +0 -41
- package/src/repositories/moderation/create-moderation.test.ts +0 -43
- package/src/repositories/moderation/create-moderation.ts +0 -45
- package/src/repositories/user/delete.test.ts +0 -35
- package/src/repositories/user/delete.ts +0 -19
- package/src/repositories/user_organisation/create-user-organization.test.ts +0 -66
- package/src/repositories/user_organisation/create-user-organization.test.ts.snapshot +0 -25
- package/src/repositories/user_organisation/create-user-organization.ts +0 -39
- package/src/repositories/user_organisation/delete-user-organization.test.ts +0 -55
- package/src/repositories/user_organisation/delete-user-organization.ts +0 -24
- package/src/repositories/user_organisation/update-user-organization.test.ts +0 -48
- package/src/repositories/user_organisation/update-user-organization.ts +0 -42
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { hashToPostgresParams } from "#src/services/postgres";
|
|
3
|
-
//
|
|
4
|
-
export function updateUserOrganizationFactory({ pg }) {
|
|
5
|
-
return async function updateUserOrganization({ organization_id, user_id }, fieldsToUpdate) {
|
|
6
|
-
const connection = pg;
|
|
7
|
-
const fieldsToUpdateWithTimestamps = {
|
|
8
|
-
...fieldsToUpdate,
|
|
9
|
-
updated_at: new Date(),
|
|
10
|
-
};
|
|
11
|
-
const { paramsString, valuesString, values } = hashToPostgresParams(fieldsToUpdateWithTimestamps);
|
|
12
|
-
const { rows } = await connection.query(`
|
|
13
|
-
UPDATE users_organizations SET ${paramsString} = ${valuesString}
|
|
14
|
-
WHERE organization_id = $${values.length + 1}
|
|
15
|
-
AND user_id = $${values.length + 2}
|
|
16
|
-
RETURNING *
|
|
17
|
-
`, [...values, organization_id, user_id]);
|
|
18
|
-
return rows.shift();
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import { deleteFranceconnectUserinfoFactory } from "./delete-franceconnect-userinfo.js";
|
|
7
|
-
import { findFranceconnectUserinfoFactory } from "./find-franceconnect-userinfo.js";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
const deleteFranceconnectUserinfo = deleteFranceconnectUserinfoFactory({
|
|
12
|
-
pg: pg as any,
|
|
13
|
-
});
|
|
14
|
-
const findFranceconnectUserinfo = findFranceconnectUserinfoFactory({
|
|
15
|
-
pg: pg as any,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("deleteFranceConnectUserInfo", () => {
|
|
19
|
-
before(migrate);
|
|
20
|
-
beforeEach(emptyDatabase);
|
|
21
|
-
|
|
22
|
-
it("should delete franceconnect user info", async () => {
|
|
23
|
-
await pg.sql`
|
|
24
|
-
INSERT INTO users
|
|
25
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
26
|
-
VALUES
|
|
27
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
28
|
-
;
|
|
29
|
-
`;
|
|
30
|
-
await pg.sql`
|
|
31
|
-
INSERT INTO franceconnect_userinfo
|
|
32
|
-
(user_id, birthdate, birthplace, family_name, gender, given_name, preferred_username, sub, created_at, updated_at)
|
|
33
|
-
VALUES
|
|
34
|
-
(1, '8888-08-08', 'Caliban', 'El''Jonson', 'male', 'Li', 'Li', 'abcdefghijklmnopqrstuvwxyz', '4444-04-04', '4444-04-04')
|
|
35
|
-
;
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
await deleteFranceconnectUserinfo(1);
|
|
39
|
-
|
|
40
|
-
const user = await findFranceconnectUserinfo(1);
|
|
41
|
-
assert.equal(user, undefined);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should not throw when deleting a user_id with no row", async () => {
|
|
45
|
-
await assert.doesNotReject(() => deleteFranceconnectUserinfo(42));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext } from "#src/types";
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
export function deleteFranceconnectUserinfoFactory({ pg }: DatabaseContext) {
|
|
8
|
-
return async function deleteFranceconnectUserinfo(user_id: number) {
|
|
9
|
-
return pg.query(
|
|
10
|
-
`
|
|
11
|
-
DELETE FROM franceconnect_userinfo
|
|
12
|
-
WHERE user_id = $1
|
|
13
|
-
`,
|
|
14
|
-
[user_id],
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type DeleteFranceconnectUserinfoHandler = ReturnType<
|
|
20
|
-
typeof deleteFranceconnectUserinfoFactory
|
|
21
|
-
>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { before, beforeEach, describe, it, mock } from "node:test";
|
|
6
|
-
import { upsertFranceconnectUserinfoFactory } from "./upsert-franceconnect-userinfo.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const upsertFranceconnectUserinfo = upsertFranceconnectUserinfoFactory({
|
|
11
|
-
pg: pg as any,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("upsertFranceconnectUserinfo", () => {
|
|
15
|
-
before(migrate);
|
|
16
|
-
beforeEach(emptyDatabase);
|
|
17
|
-
before(() => {
|
|
18
|
-
mock.timers.enable({ apis: ["Date"], now: new Date("4444-04-04") });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should insert a user franceconnect userinfo", async () => {
|
|
22
|
-
await pg.sql`
|
|
23
|
-
INSERT INTO users
|
|
24
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
25
|
-
VALUES
|
|
26
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
27
|
-
;
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
|
-
const user = await upsertFranceconnectUserinfo({
|
|
31
|
-
birthdate: new Date("8888-08-08"),
|
|
32
|
-
birthplace: "Caliban",
|
|
33
|
-
created_at: new Date("4444-04-01"),
|
|
34
|
-
family_name: "El’Jonson",
|
|
35
|
-
gender: "male",
|
|
36
|
-
given_name: "Lion",
|
|
37
|
-
preferred_username: "Li",
|
|
38
|
-
sub: "abcdefghijklmnopqrstuvwxyz",
|
|
39
|
-
updated_at: new Date("4444-04-02"),
|
|
40
|
-
user_id: 1,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
assert.deepEqual(user, {
|
|
44
|
-
birthcountry: null,
|
|
45
|
-
birthdate: new Date("8888-08-08"),
|
|
46
|
-
birthplace: "Caliban",
|
|
47
|
-
created_at: new Date("4444-04-01"),
|
|
48
|
-
family_name: "El’Jonson",
|
|
49
|
-
gender: "male",
|
|
50
|
-
given_name: "Lion",
|
|
51
|
-
preferred_username: "Li",
|
|
52
|
-
sub: "abcdefghijklmnopqrstuvwxyz",
|
|
53
|
-
updated_at: new Date("4444-04-04"),
|
|
54
|
-
user_id: 1,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should update a user Verification link", async () => {
|
|
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
|
-
await pg.sql`
|
|
67
|
-
INSERT INTO franceconnect_userinfo
|
|
68
|
-
(user_id, created_at, updated_at, given_name)
|
|
69
|
-
VALUES
|
|
70
|
-
(1, '4444-04-01', '4444-04-02', 'Lion')
|
|
71
|
-
;
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
const user = await upsertFranceconnectUserinfo({
|
|
75
|
-
user_id: 1,
|
|
76
|
-
preferred_username: "Li",
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
assert.deepEqual(user, {
|
|
80
|
-
birthcountry: null,
|
|
81
|
-
birthdate: null,
|
|
82
|
-
birthplace: null,
|
|
83
|
-
created_at: new Date("4444-04-01"),
|
|
84
|
-
family_name: null,
|
|
85
|
-
gender: null,
|
|
86
|
-
given_name: "Lion",
|
|
87
|
-
preferred_username: "Li",
|
|
88
|
-
sub: null,
|
|
89
|
-
updated_at: new Date("4444-04-04"),
|
|
90
|
-
user_id: 1,
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("❎ fail to update an unknown user", async () => {
|
|
95
|
-
await assert.rejects(
|
|
96
|
-
upsertFranceconnectUserinfo({
|
|
97
|
-
user_id: 42,
|
|
98
|
-
}),
|
|
99
|
-
`error: insert or update on table "franceconnect_userinfo" violates foreign key constraint "franceconnect_userinfo_user_id_fkey"`,
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { hashToPostgresParams } from "#src/services/postgres";
|
|
4
|
-
import type { DatabaseContext, FranceConnectUserInfo } from "#src/types";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export function upsertFranceconnectUserinfoFactory({ pg }: DatabaseContext) {
|
|
9
|
-
return async function upsertFranceconnectUserinfo(
|
|
10
|
-
value: Pick<FranceConnectUserInfo, "user_id"> &
|
|
11
|
-
Partial<FranceConnectUserInfo>,
|
|
12
|
-
) {
|
|
13
|
-
const fieldsWithTimestamps = {
|
|
14
|
-
...value,
|
|
15
|
-
updated_at: new Date(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const { paramsString, valuesString, values } =
|
|
19
|
-
hashToPostgresParams<FranceConnectUserInfo>(fieldsWithTimestamps);
|
|
20
|
-
|
|
21
|
-
const { rows } = await pg.query<FranceConnectUserInfo>(
|
|
22
|
-
`
|
|
23
|
-
INSERT INTO franceconnect_userinfo
|
|
24
|
-
${paramsString}
|
|
25
|
-
VALUES
|
|
26
|
-
${valuesString}
|
|
27
|
-
ON CONFLICT (user_id)
|
|
28
|
-
DO UPDATE
|
|
29
|
-
SET ${paramsString} = ${valuesString}
|
|
30
|
-
RETURNING *
|
|
31
|
-
`,
|
|
32
|
-
[...values],
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return rows.shift()!;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type UpsetFranceconnectUserinfoHandler = ReturnType<
|
|
40
|
-
typeof upsertFranceconnectUserinfoFactory
|
|
41
|
-
>;
|
|
@@ -1,43 +0,0 @@
|
|
|
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 { createModerationFactory } from "./create-moderation.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const createModeration = createModerationFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("createModerationFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should insert and return the moderation", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO organizations
|
|
19
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
20
|
-
VALUES
|
|
21
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
await pg.sql`
|
|
25
|
-
INSERT INTO users
|
|
26
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
27
|
-
VALUES
|
|
28
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
29
|
-
;
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const moderation = await createModeration({
|
|
33
|
-
user_id: 1,
|
|
34
|
-
organization_id: 1,
|
|
35
|
-
type: "organization_join_block",
|
|
36
|
-
ticket_id: null,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
assert.equal(moderation.user_id, 1);
|
|
40
|
-
assert.equal(moderation.organization_id, 1);
|
|
41
|
-
assert.equal(moderation.status, "pending");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ModerationStatusSchema,
|
|
5
|
-
type DatabaseContext,
|
|
6
|
-
type Moderation,
|
|
7
|
-
type ModerationType,
|
|
8
|
-
} from "#src/types";
|
|
9
|
-
import { type QueryResult } from "pg";
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
export function createModerationFactory({ pg }: DatabaseContext) {
|
|
14
|
-
return async function createModeration({
|
|
15
|
-
user_id,
|
|
16
|
-
organization_id,
|
|
17
|
-
sp_name,
|
|
18
|
-
type,
|
|
19
|
-
ticket_id,
|
|
20
|
-
}: {
|
|
21
|
-
user_id: number;
|
|
22
|
-
organization_id: number;
|
|
23
|
-
sp_name?: string;
|
|
24
|
-
type: ModerationType;
|
|
25
|
-
ticket_id: string | null;
|
|
26
|
-
}) {
|
|
27
|
-
const { rows }: QueryResult<Moderation> = await pg.query(
|
|
28
|
-
`
|
|
29
|
-
INSERT INTO moderations (user_id, organization_id, status, type, ticket_id, sp_name, allow_editing)
|
|
30
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
31
|
-
RETURNING *;`,
|
|
32
|
-
[
|
|
33
|
-
user_id,
|
|
34
|
-
organization_id,
|
|
35
|
-
ModerationStatusSchema.enum.pending,
|
|
36
|
-
type,
|
|
37
|
-
ticket_id,
|
|
38
|
-
sp_name ?? null,
|
|
39
|
-
false,
|
|
40
|
-
],
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return rows.shift()!;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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 { deleteUserFactory } from "./delete.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const deleteUser = deleteUserFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("deleteUserFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should return true when the user exists", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO users
|
|
19
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
20
|
-
VALUES
|
|
21
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
const result = await deleteUser(1);
|
|
26
|
-
|
|
27
|
-
assert.equal(result, true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("should return false when the user does not exist", async () => {
|
|
31
|
-
const result = await deleteUser(999);
|
|
32
|
-
|
|
33
|
-
assert.equal(result, false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext } from "#src/types";
|
|
4
|
-
import { type QueryResult } from "pg";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export function deleteUserFactory({ pg }: DatabaseContext) {
|
|
9
|
-
return async function deleteUser(id: number) {
|
|
10
|
-
const { rowCount, affectedRows } = (await pg.query(
|
|
11
|
-
`
|
|
12
|
-
DELETE FROM users
|
|
13
|
-
WHERE id = $1`,
|
|
14
|
-
[id],
|
|
15
|
-
)) as QueryResult & { affectedRows?: number };
|
|
16
|
-
|
|
17
|
-
return (affectedRows ?? rowCount ?? 0) > 0;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { LinkEnum } from "#src/types";
|
|
2
|
-
import { emptyDatabase, migrate, pg } from "#testing";
|
|
3
|
-
import { before, beforeEach, mock, suite, test } from "node:test";
|
|
4
|
-
import { createUserOrganizationFactory } from "./create-user-organization.js";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
const linkUserToOrganization = createUserOrganizationFactory({ pg: pg as any });
|
|
9
|
-
|
|
10
|
-
suite("linkUserToOrganizationFactory", () => {
|
|
11
|
-
before(migrate);
|
|
12
|
-
beforeEach(emptyDatabase);
|
|
13
|
-
before(() => {
|
|
14
|
-
mock.timers.enable({ apis: ["Date"], now: new Date("4444-04-04") });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("should link user to organization", async (t) => {
|
|
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 userOrganizationLink = await linkUserToOrganization({
|
|
34
|
-
organization_id: 1,
|
|
35
|
-
user_id: 1,
|
|
36
|
-
verification_type: LinkEnum.enum.domain_not_verified_yet,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
t.assert.snapshot(userOrganizationLink);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("should mark a user as organization_dirigeant", async (t) => {
|
|
43
|
-
await pg.sql`
|
|
44
|
-
INSERT INTO organizations
|
|
45
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
46
|
-
VALUES
|
|
47
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
48
|
-
;
|
|
49
|
-
`;
|
|
50
|
-
await pg.sql`
|
|
51
|
-
INSERT INTO users
|
|
52
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
53
|
-
VALUES
|
|
54
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
55
|
-
;
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
const userOrganizationLink = await linkUserToOrganization({
|
|
59
|
-
organization_id: 1,
|
|
60
|
-
user_id: 1,
|
|
61
|
-
verification_type: LinkEnum.enum.organization_dirigeant,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
t.assert.snapshot(userOrganizationLink);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
exports[`linkUserToOrganizationFactory > should link user to organization 1`] = `
|
|
2
|
-
{
|
|
3
|
-
"user_id": 1,
|
|
4
|
-
"organization_id": 1,
|
|
5
|
-
"is_external": false,
|
|
6
|
-
"created_at": "4444-04-04T00:00:00.000Z",
|
|
7
|
-
"updated_at": "4444-04-04T00:00:00.000Z",
|
|
8
|
-
"verification_type": "domain_not_verified_yet",
|
|
9
|
-
"has_been_greeted": false,
|
|
10
|
-
"verified_at": "4444-04-04T00:00:00.000Z"
|
|
11
|
-
}
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
exports[`linkUserToOrganizationFactory > should mark a user as organization_dirigeant 1`] = `
|
|
15
|
-
{
|
|
16
|
-
"user_id": 1,
|
|
17
|
-
"organization_id": 1,
|
|
18
|
-
"is_external": false,
|
|
19
|
-
"created_at": "4444-04-04T00:00:00.000Z",
|
|
20
|
-
"updated_at": "4444-04-04T00:00:00.000Z",
|
|
21
|
-
"verification_type": "organization_dirigeant",
|
|
22
|
-
"has_been_greeted": false,
|
|
23
|
-
"verified_at": "4444-04-04T00:00:00.000Z"
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { hashToPostgresParams } from "#src/services/postgres";
|
|
2
|
-
import type {
|
|
3
|
-
DatabaseContext,
|
|
4
|
-
InsertUserOrganizationLink,
|
|
5
|
-
UserOrganizationLink,
|
|
6
|
-
} from "#src/types";
|
|
7
|
-
import type { QueryResult } from "pg";
|
|
8
|
-
|
|
9
|
-
export function createUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
10
|
-
return async function linkUserToOrganization({
|
|
11
|
-
is_external = false,
|
|
12
|
-
organization_id,
|
|
13
|
-
user_id,
|
|
14
|
-
verification_type,
|
|
15
|
-
}: InsertUserOrganizationLink) {
|
|
16
|
-
const { paramsString, valuesString, values } =
|
|
17
|
-
hashToPostgresParams<UserOrganizationLink>({
|
|
18
|
-
created_at: new Date(),
|
|
19
|
-
is_external,
|
|
20
|
-
organization_id,
|
|
21
|
-
updated_at: new Date(),
|
|
22
|
-
user_id,
|
|
23
|
-
verification_type,
|
|
24
|
-
verified_at: verification_type ? new Date() : undefined,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const { rows }: QueryResult<UserOrganizationLink> = await pg.query(
|
|
28
|
-
`
|
|
29
|
-
INSERT INTO users_organizations
|
|
30
|
-
${paramsString}
|
|
31
|
-
VALUES
|
|
32
|
-
${valuesString}
|
|
33
|
-
RETURNING *;`,
|
|
34
|
-
values,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
return rows.shift()!;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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 { deleteUserOrganizationFactory } from "./delete-user-organization.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const deleteUserOrganization = deleteUserOrganizationFactory({ pg: pg as any });
|
|
11
|
-
|
|
12
|
-
suite("deleteUserOrganizationFactory", () => {
|
|
13
|
-
before(migrate);
|
|
14
|
-
beforeEach(emptyDatabase);
|
|
15
|
-
|
|
16
|
-
test("should return true when the link exists", async () => {
|
|
17
|
-
await pg.sql`
|
|
18
|
-
INSERT INTO organizations
|
|
19
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
20
|
-
VALUES
|
|
21
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
22
|
-
;
|
|
23
|
-
`;
|
|
24
|
-
await pg.sql`
|
|
25
|
-
INSERT INTO users
|
|
26
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
27
|
-
VALUES
|
|
28
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
29
|
-
;
|
|
30
|
-
`;
|
|
31
|
-
await pg.sql`
|
|
32
|
-
INSERT INTO users_organizations
|
|
33
|
-
(user_id, organization_id, created_at, updated_at, verification_type)
|
|
34
|
-
VALUES
|
|
35
|
-
(1, 1, '4444-04-04', '4444-04-04', 'domain_not_verified_yet')
|
|
36
|
-
;
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const result = await deleteUserOrganization({
|
|
40
|
-
user_id: 1,
|
|
41
|
-
organization_id: 1,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
assert.equal(result, true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("should return false when the link does not exist", async () => {
|
|
48
|
-
const result = await deleteUserOrganization({
|
|
49
|
-
user_id: 999,
|
|
50
|
-
organization_id: 999,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
assert.equal(result, false);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
|
|
4
|
-
import type { QueryResult } from "pg";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export function deleteUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
9
|
-
return async function deleteUserOrganization({
|
|
10
|
-
user_id,
|
|
11
|
-
organization_id,
|
|
12
|
-
}: FindUserOrganizationLink) {
|
|
13
|
-
const { rowCount, affectedRows } = (await pg.query(
|
|
14
|
-
`
|
|
15
|
-
DELETE
|
|
16
|
-
FROM users_organizations
|
|
17
|
-
WHERE user_id = $1
|
|
18
|
-
AND organization_id = $2`,
|
|
19
|
-
[user_id, organization_id],
|
|
20
|
-
)) as QueryResult & { affectedRows?: number };
|
|
21
|
-
|
|
22
|
-
return (affectedRows ?? rowCount ?? 0) > 0;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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 { updateUserOrganizationFactory } from "./update-user-organization.js";
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
const updateUserOrganization = updateUserOrganizationFactory({
|
|
11
|
-
pg: pg as any,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
suite("updateUserOrganizationLink", () => {
|
|
15
|
-
before(migrate);
|
|
16
|
-
beforeEach(emptyDatabase);
|
|
17
|
-
|
|
18
|
-
test("should update the user organization link", async () => {
|
|
19
|
-
await pg.sql`
|
|
20
|
-
INSERT INTO organizations
|
|
21
|
-
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
22
|
-
VALUES
|
|
23
|
-
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
24
|
-
;
|
|
25
|
-
`;
|
|
26
|
-
await pg.sql`
|
|
27
|
-
INSERT INTO users
|
|
28
|
-
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
29
|
-
VALUES
|
|
30
|
-
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque')
|
|
31
|
-
;
|
|
32
|
-
`;
|
|
33
|
-
await pg.sql`
|
|
34
|
-
INSERT INTO users_organizations
|
|
35
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
36
|
-
VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available')
|
|
37
|
-
;
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
const user = await updateUserOrganization(
|
|
41
|
-
{ organization_id: 1, user_id: 1 },
|
|
42
|
-
{
|
|
43
|
-
is_external: true,
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
assert.ok(user.is_external);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { hashToPostgresParams } from "#src/services/postgres";
|
|
4
|
-
import type {
|
|
5
|
-
DatabaseContext,
|
|
6
|
-
FindUserOrganizationLink,
|
|
7
|
-
User,
|
|
8
|
-
UserOrganizationLink,
|
|
9
|
-
} from "#src/types";
|
|
10
|
-
import type { QueryResult } from "pg";
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
export function updateUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
15
|
-
return async function updateUserOrganization(
|
|
16
|
-
{ organization_id, user_id }: FindUserOrganizationLink,
|
|
17
|
-
fieldsToUpdate: Partial<UserOrganizationLink>,
|
|
18
|
-
) {
|
|
19
|
-
const connection = pg;
|
|
20
|
-
|
|
21
|
-
const fieldsToUpdateWithTimestamps = {
|
|
22
|
-
...fieldsToUpdate,
|
|
23
|
-
updated_at: new Date(),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const { paramsString, valuesString, values } = hashToPostgresParams<User>(
|
|
27
|
-
fieldsToUpdateWithTimestamps,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const { rows }: QueryResult<UserOrganizationLink> = await connection.query(
|
|
31
|
-
`
|
|
32
|
-
UPDATE users_organizations SET ${paramsString} = ${valuesString}
|
|
33
|
-
WHERE organization_id = $${values.length + 1}
|
|
34
|
-
AND user_id = $${values.length + 2}
|
|
35
|
-
RETURNING *
|
|
36
|
-
`,
|
|
37
|
-
[...values, organization_id, user_id],
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
return rows.shift()!;
|
|
41
|
-
};
|
|
42
|
-
}
|