-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(moderation): remove member when reproessing a moderation
- Loading branch information
1 parent
0f8d383
commit cc33db7
Showing
20 changed files
with
288 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,3 @@ Fonctionnalité: Moderation blockante à refuser | |
Quand sur la même ligne je clique sur "➡️" | ||
Alors je vois "Jean Bon veut rejoindre l'organisation « DINUM » avec l’adresse [email protected]" | ||
|
||
# Quand je clique sur "Sélectionner une response" | ||
# * je sélectionne "Quel lien avec l'organisation ?" | ||
# * je clique "🪄 Marquer comme traité" |
25 changes: 25 additions & 0 deletions
25
e2e/features/moderations/reprocess_marie_bon_bosch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
#language: fr | ||
Fonctionnalité: Retraiter une moderation | ||
|
||
Contexte: | ||
Soit une base de données nourrie au grain | ||
Quand je navigue sur la page | ||
* je vois "Bonjour Hyyypertool !" | ||
* je clique sur le bouton "ProConnect" | ||
Alors je vois "Liste des moderations" | ||
* je clique sur "Voir les demandes traitées" | ||
* je clique sur "Filtrer par jours" | ||
* je tape "2011-11-12" | ||
* je vois la ligne de table "44023386400014" | ||
* sur la même ligne je clique sur "✅" | ||
* je vois "Cette modération a été marqué comme traité" | ||
* je vois "Marie Bon a rejoint une organisation avec un domain non vérifié « Bosch rexroth d.s.i. »" | ||
|
||
@only | ||
Scénario: Marie Bon à rejoindre l'organisation Bosch par erreur | ||
Quand je clique sur "Retraiter" | ||
Alors je ne vois pas "Cette modération a été marqué comme traité" | ||
|
||
Soit le tableau sous le title "membre connu dans l’organisation" | ||
Alors le tableau est vide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ Fonctionnalité: Duplicate Moderation | |
* sur la même ligne je vois "Richard" | ||
* sur la même ligne je vois "[email protected]" | ||
|
||
# Scénario: | ||
Quand sur la même ligne je clique sur "➡️" | ||
Alors je vois "Richard Bon veut rejoindre l'organisation « Dengi - Leclerc »" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/~/moderations/lib/src/usecase/ReprocessModerationById.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
|
||
import { beforeAll, expect, mock, setSystemTime, test } from "bun:test"; | ||
import { ReprocessModerationById } from "./ReprocessModerationById"; | ||
|
||
// | ||
|
||
const userinfo = { email: "[email protected]" }; | ||
|
||
beforeAll(() => { | ||
setSystemTime(new Date("2222-01-01T00:00:00.000Z")); | ||
}); | ||
|
||
test("reprocess a moderation", async () => { | ||
const get_moderation_by_id = mock().mockResolvedValueOnce({ | ||
comment: "", | ||
organization_id: 1, | ||
user_id: 1, | ||
}); | ||
const update_moderation_by_id = mock(); | ||
const remove_user_from_organization = mock(); | ||
|
||
const reprocess_moderation_by_id = ReprocessModerationById({ | ||
get_moderation_by_id, | ||
update_moderation_by_id, | ||
remove_user_from_organization, | ||
userinfo, | ||
}); | ||
await reprocess_moderation_by_id(1); | ||
|
||
expect(get_moderation_by_id).toHaveBeenLastCalledWith(1, { | ||
columns: { | ||
comment: true, | ||
organization_id: true, | ||
user_id: true, | ||
}, | ||
}); | ||
expect(update_moderation_by_id).toHaveBeenLastCalledWith(1, { | ||
comment: "7952342400000 [email protected] | Réouverte par [email protected]", | ||
moderated_by: null, | ||
moderated_at: null, | ||
}); | ||
expect(remove_user_from_organization).toHaveBeenLastCalledWith({ | ||
organization_id: 1, | ||
user_id: 1, | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
packages/~/moderations/lib/src/usecase/ReprocessModerationById.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
|
||
import type { | ||
GetModerationByIdHandler, | ||
RemoveUserFromOrganizationHandler, | ||
UpdateModerationByIdHandler, | ||
} from "@~/moderations.repository"; | ||
import { append_comment } from "../comment_message"; | ||
|
||
// | ||
|
||
export function ReprocessModerationById({ | ||
get_moderation_by_id, | ||
remove_user_from_organization, | ||
update_moderation_by_id, | ||
userinfo, | ||
}: { | ||
get_moderation_by_id: GetModerationByIdHandler; | ||
remove_user_from_organization: RemoveUserFromOrganizationHandler; | ||
update_moderation_by_id: UpdateModerationByIdHandler; | ||
userinfo: { email: string }; | ||
}) { | ||
return async function reprocess_moderation_by_id(id: number) { | ||
const moderation = await get_moderation_by_id(id, { | ||
columns: { comment: true, organization_id: true, user_id: true }, | ||
}); | ||
|
||
const comment = append_comment(moderation.comment, { | ||
type: "REPROCESSED", | ||
created_by: userinfo.email, | ||
}); | ||
|
||
await remove_user_from_organization({ | ||
organization_id: moderation.organization_id, | ||
user_id: moderation.user_id, | ||
}); | ||
|
||
await update_moderation_by_id(id, { | ||
comment, | ||
moderated_by: null, | ||
moderated_at: null, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/~/moderations/repository/src/RemoveUserFromOrganization.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
|
||
import { schema } from "@~/moncomptepro.database"; | ||
import { | ||
create_adora_pony_user, | ||
create_unicorn_organization, | ||
} from "@~/moncomptepro.database/seed/unicorn"; | ||
import { empty_database, migrate, pg } from "@~/moncomptepro.database/testing"; | ||
import { beforeAll, beforeEach, expect, setSystemTime, test } from "bun:test"; | ||
import { RemoveUserFromOrganization } from "./RemoveUserFromOrganization"; | ||
|
||
// | ||
|
||
beforeAll(migrate); | ||
beforeEach(empty_database); | ||
|
||
beforeAll(() => { | ||
setSystemTime(new Date("2222-01-01T00:00:00.000Z")); | ||
}); | ||
|
||
// | ||
|
||
test("remove adora from unicorn organization", async () => { | ||
const unicorn_organization_id = await create_unicorn_organization(pg); | ||
const adora_pony_user_id = await create_adora_pony_user(pg); | ||
|
||
await pg.insert(schema.users_organizations).values({ | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
}); | ||
|
||
const remove_user_from_organization = RemoveUserFromOrganization({ pg }); | ||
const response = await remove_user_from_organization({ | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
}); | ||
|
||
expect(response).toEqual({ | ||
affectedRows: 1, | ||
fields: [], | ||
rows: [], | ||
}); | ||
}); | ||
|
||
test("do nothing if adora is not a unicorn member", async () => { | ||
const unicorn_organization_id = await create_unicorn_organization(pg); | ||
const adora_pony_user_id = await create_adora_pony_user(pg); | ||
|
||
const remove_user_from_organization = RemoveUserFromOrganization({ pg }); | ||
const response = await remove_user_from_organization({ | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
}); | ||
|
||
expect(response).toEqual({ | ||
affectedRows: 0, | ||
fields: [], | ||
rows: [], | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/~/moderations/repository/src/RemoveUserFromOrganization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
|
||
import { | ||
schema, | ||
type MonCompteProDatabaseCradle, | ||
} from "@~/moncomptepro.database"; | ||
import type { UserOrganizationIdPair } from "@~/organizations.lib/entities/Organization"; | ||
import { and, eq } from "drizzle-orm"; | ||
|
||
// | ||
|
||
export function RemoveUserFromOrganization({ pg }: MonCompteProDatabaseCradle) { | ||
return async function remove_user_from_organization({ | ||
organization_id, | ||
user_id, | ||
}: UserOrganizationIdPair) { | ||
return pg | ||
.delete(schema.users_organizations) | ||
.where( | ||
and( | ||
eq(schema.users_organizations.organization_id, organization_id), | ||
eq(schema.users_organizations.user_id, user_id), | ||
), | ||
); | ||
}; | ||
} | ||
|
||
export type RemoveUserFromOrganizationHandler = ReturnType< | ||
typeof RemoveUserFromOrganization | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.