Skip to content

Commit 881dbde

Browse files
feat(users): gmail gouv users kpi (#561)
1 parent 4726159 commit 881dbde

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

hyyypertool.code-workspace

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@
201201
"problemMatcher": ["$tsc-watch"],
202202
"runOptions": { "instanceLimit": 1 },
203203
},
204+
{
205+
"label": "🧪 Watch Test : Current file",
206+
"command": "bun test --watch ${fileDirname}/${fileBasename}",
207+
"type": "shell",
208+
"group": "build",
209+
"options": {
210+
"cwd": "${workspaceFolder:root}",
211+
},
212+
"problemMatcher": ["$tsc-watch"],
213+
"runOptions": { "instanceLimit": 1 },
214+
},
204215
{
205216
"label": "🧪 Cypress Studio",
206217
"command": "pnpm run studio",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
3+
import {
4+
create_pink_diamond_user,
5+
create_red_diamond_user,
6+
create_unicorn_organization,
7+
} from "@~/moncomptepro.database/seed/unicorn";
8+
import {
9+
add_user_to_organization,
10+
empty_database,
11+
migrate,
12+
pg,
13+
} from "@~/moncomptepro.database/testing";
14+
import { beforeAll, beforeEach, expect, test } from "bun:test";
15+
import { count_gmail_members } from "./count_gmail_members";
16+
17+
//
18+
19+
beforeAll(migrate);
20+
beforeEach(empty_database);
21+
22+
test("returns pink diamond", async () => {
23+
const unicorn_organization_id = await create_unicorn_organization(pg);
24+
const pink_diamond_user_id = await create_pink_diamond_user(pg);
25+
await add_user_to_organization({
26+
organization_id: unicorn_organization_id,
27+
user_id: pink_diamond_user_id,
28+
});
29+
const red_diamond_user_id = await create_red_diamond_user(pg);
30+
await add_user_to_organization({
31+
organization_id: unicorn_organization_id,
32+
user_id: red_diamond_user_id,
33+
});
34+
35+
const emails = await count_gmail_members(pg, {
36+
siret: "🦄",
37+
domain: "@unicorn.xyz",
38+
});
39+
40+
expect(emails).toEqual([
41+
{
42+
email: "pink.diamond@unicorn.xyz",
43+
organization: {
44+
cached_libelle: "🦄 libelle",
45+
siret: "🦄 siret",
46+
},
47+
},
48+
{
49+
email: "red.diamond@unicorn.xyz",
50+
organization: {
51+
cached_libelle: "🦄 libelle",
52+
siret: "🦄 siret",
53+
},
54+
},
55+
]);
56+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
3+
import { schema, type MonComptePro_PgDatabase } from "@~/moncomptepro.database";
4+
import { and, eq, like } from "drizzle-orm";
5+
6+
//
7+
8+
export async function count_gmail_members(
9+
pg: MonComptePro_PgDatabase,
10+
{ domain, siret }: { domain: string; siret: string },
11+
) {
12+
return pg
13+
.select({
14+
email: schema.users.email,
15+
organization: {
16+
cached_libelle: schema.organizations.cached_libelle,
17+
siret: schema.organizations.siret,
18+
},
19+
})
20+
.from(schema.users)
21+
.innerJoin(
22+
schema.users_organizations,
23+
eq(schema.users.id, schema.users_organizations.user_id),
24+
)
25+
.innerJoin(
26+
schema.organizations,
27+
eq(schema.users_organizations.organization_id, schema.organizations.id),
28+
)
29+
.where(
30+
and(
31+
like(schema.organizations.siret, `${siret}%`),
32+
like(schema.users.email, `%${domain}`),
33+
),
34+
);
35+
}
36+
37+
export type count_gmail_members_dto = ReturnType<typeof count_gmail_members>;

0 commit comments

Comments
 (0)