Skip to content

Commit

Permalink
rename roles using kebab case : back-office to-review agency-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementLmd committed Sep 23, 2024
1 parent 075a523 commit 191722e
Show file tree
Hide file tree
Showing 41 changed files with 144 additions and 136 deletions.
20 changes: 10 additions & 10 deletions back/src/adapters/primary/routers/admin/adminRouter.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ describe("Admin router", () => {
describe(`${displayRouteName(
adminRoutes.getInclusionConnectedUsers,
)} List inclusion connected user`, () => {
it("200 - Gets the list of connected users with role 'toReview'", async () => {
it("200 - Gets the list of connected users with role 'to-review'", async () => {
const response = await sharedRequest.getInclusionConnectedUsers({
queryParams: { agencyRole: "toReview" },
queryParams: { agencyRole: "to-review" },
headers: { authorization: token },
});
expectHttpResponseToEqual(response, {
Expand All @@ -367,7 +367,7 @@ describe("Admin router", () => {

it("401 - missing token", async () => {
const response = await sharedRequest.getInclusionConnectedUsers({
queryParams: { agencyRole: "toReview" },
queryParams: { agencyRole: "to-review" },
headers: { authorization: "" },
});
expectHttpResponseToEqual(response, {
Expand All @@ -380,7 +380,7 @@ describe("Admin router", () => {
describe(`${displayRouteName(
adminRoutes.updateUserRoleForAgency,
)} Update user role for agency`, () => {
it("201 - Updates role of user from 'toReview' to 'counsellor' for given agency", async () => {
it("201 - Updates role of user from 'to-review' to 'counsellor' for given agency", async () => {
const agency = new AgencyDtoBuilder()
.withId("two-steps-validation-agency")
.withCounsellorEmails(["[email protected]"])
Expand All @@ -391,7 +391,7 @@ describe("Admin router", () => {
firstName: "John",
lastName: "Doe",
agencyRights: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-external-id",
Expand Down Expand Up @@ -435,15 +435,15 @@ describe("Admin router", () => {
});
});

it("400 - when trying to Update role of user from 'toReview' to 'counsellor' for agency that have only one step validation", async () => {
it("400 - when trying to Update role of user from 'to-review' to 'counsellor' for agency that have only one step validation", async () => {
const agency = new AgencyDtoBuilder().build();
const inclusionConnectedUser: InclusionConnectedUser = {
id: "my-user-id",
email: "[email protected]",
firstName: "John",
lastName: "Doe",
agencyRights: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-external-id",
Expand Down Expand Up @@ -489,7 +489,7 @@ describe("Admin router", () => {

expectObjectsToMatch(inMemoryUow.userRepository.agencyRightsByUserId, {
[inclusionConnectedUser.id]: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
});
});
Expand Down Expand Up @@ -520,7 +520,7 @@ describe("Admin router", () => {
firstName: "John",
lastName: "Doe",
agencyRights: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-external-id",
Expand Down Expand Up @@ -563,7 +563,7 @@ describe("Admin router", () => {
firstName: "John",
lastName: "Doe",
agencyRights: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-external-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe("InclusionConnectedAllowedRoutes", () => {
expectToEqual(await inMemoryUow.userRepository.getById(userId), {
...inclusionConnectedUserWithRights,
agencyRights: [
{ agency, roles: ["toReview"], isNotifiedByEmail: false },
{ agency, roles: ["to-review"], isNotifiedByEmail: false },
],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class RegisterAgencyToInclusionConnectUser extends TransactionalUseCase<
userId: user.id,
agencyRights: agencies.map((agency) => ({
agency,
roles: ["toReview"],
roles: ["to-review"],
isNotifiedByEmail: false,
})),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("RegisterAgencyToInclusionConnectUser use case", () => {
expectToEqual(inclusionConnectedUser, {
...user,
agencyRights: [
{ agency: agency1, roles: ["toReview"], isNotifiedByEmail: false },
{ agency: agency1, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
});
Expand Down Expand Up @@ -137,8 +137,8 @@ describe("RegisterAgencyToInclusionConnectUser use case", () => {
expectToEqual(inclusionConnectedUser, {
...user,
agencyRights: [
{ agency: agency1, roles: ["toReview"], isNotifiedByEmail: false },
{ agency: agency2, roles: ["toReview"], isNotifiedByEmail: false },
{ agency: agency1, roles: ["to-review"], isNotifiedByEmail: false },
{ agency: agency2, roles: ["to-review"], isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
});
Expand Down
2 changes: 1 addition & 1 deletion back/src/domains/convention/use-cases/GetConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class GetConvention extends TransactionalUseCase<
conventionId: ConventionId,
): authPayload is InclusionConnectJwtPayload {
if (!("role" in authPayload)) return true;
if (authPayload.role === "backOffice") return false;
if (authPayload.role === "back-office") return false;
if (authPayload.applicationId === conventionId) return false;
throw new ForbiddenError(
`This token is not allowed to access convention with id ${conventionId}. Role was '${authPayload.role}'`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Get Convention", () => {
firstName: "John",
lastName: "Doe",
agencyRights: [
{ roles: ["toReview"], agency, isNotifiedByEmail: false },
{ roles: ["to-review"], agency, isNotifiedByEmail: false },
],
dashboards: { agencies: {}, establishments: {} },
externalId: "john-external-id",
Expand Down
4 changes: 2 additions & 2 deletions back/src/domains/convention/use-cases/RenewConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class RenewConvention extends TransactionalUseCase<
uow: UnitOfWork,
jwtPayload?: ConventionRelatedJwtPayload,
): Promise<void> {
const allowedRoles: Role[] = ["validator", "counsellor", "backOffice"];
const allowedRoles: Role[] = ["validator", "counsellor", "back-office"];

if (!jwtPayload) throw errors.user.unauthorized();

Expand Down Expand Up @@ -100,7 +100,7 @@ export class RenewConvention extends TransactionalUseCase<
`Inclusion connected user '${jwtPayload.userId}' not found.`,
);

if (inclusionConnectedUser.isBackofficeAdmin) return ["backOffice"];
if (inclusionConnectedUser.isBackofficeAdmin) return ["back-office"];

const agencyRight = inclusionConnectedUser.agencyRights.find(
(agencyRight) => agencyRight.agency.id === convention.agencyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ describe("RenewConvention", () => {
{
...inclusionConnectedUser,
agencyRights: [
{ agency, roles: ["agencyAdmin"], isNotifiedByEmail: false },
{ agency, roles: ["agency-admin"], isNotifiedByEmail: false },
],
},
]);
await expectPromiseToFailWithError(
renewConvention.execute(renewConventionParams, inclusionConnectPayload),
new ForbiddenError(
"The role 'agencyAdmin' is not allowed to renew convention",
"The role 'agency-admin' is not allowed to renew convention",
),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe("RenewConventionMagicLink use case", () => {
it("Refuses to generate backoffice magic links", async () => {
const payload = createConventionMagicLinkPayload({
id: validConvention.id,
role: "backOffice",
role: "back-office",
email,
now: timeGateway.now(),
});
Expand All @@ -250,7 +250,7 @@ describe("RenewConventionMagicLink use case", () => {

await expectPromiseToFailWithError(
useCase.execute(request),
errors.convention.roleHasNoMagicLink({ role: "backOffice" }),
errors.convention.roleHasNoMagicLink({ role: "back-office" }),
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ const makeUserIdMapInclusionConnectedUser: Record<
agencyRights: [
{
agency: agencyWithoutCounsellorEmail,
roles: ["toReview"],
roles: ["to-review"],
isNotifiedByEmail: false,
},
{
agency: agencyWithCounsellorEmails,
roles: ["toReview"],
roles: ["to-review"],
isNotifiedByEmail: false,
},
],
Expand Down Expand Up @@ -165,12 +165,12 @@ const makeUserIdMapInclusionConnectedUser: Record<
agencyRights: [
{
agency: agencyWithoutCounsellorEmail,
roles: ["agencyAdmin"],
roles: ["agency-admin"],
isNotifiedByEmail: false,
},
{
agency: agencyWithCounsellorEmails,
roles: ["agencyAdmin"],
roles: ["agency-admin"],
isNotifiedByEmail: false,
},
],
Expand Down Expand Up @@ -607,7 +607,7 @@ export const rejectStatusTransitionTests = ({
if (user.email === establishmentRepEmail)
return ["establishment-representative"];

if (user.isBackofficeAdmin) return ["backOffice"];
if (user.isBackofficeAdmin) return ["back-office"];

return (
user.agencyRights.find(
Expand Down Expand Up @@ -730,7 +730,7 @@ const defineRolesForTest = (
return ["establishment-representative"];

if (testAcceptNewStatusParams.userId === "icUserWithRoleBackofficeAdmin")
return ["backOffice"];
return ["back-office"];

const roles =
makeUserIdMapInclusionConnectedUser[
Expand All @@ -754,8 +754,8 @@ export const agencyRolesEmptyOrContainsToReviewOrAgencyAdmin = (
roles: (AgencyRole | Role)[],
): roles is ExcludeFromExisting<
AgencyRole | Role,
"toReview" | "agencyAdmin"
"to-review" | "agency-admin"
>[] =>
roles.length === 0 ||
roles.includes("toReview") ||
roles.includes("agencyAdmin");
roles.includes("to-review") ||
roles.includes("agency-admin");
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class UpdateConventionStatus extends TransactionalUseCase<
convention: ConventionDto,
): Promise<Role[]> {
const roles: Role[] = [];
if (user.isBackofficeAdmin) roles.push("backOffice");
if (user.isBackofficeAdmin) roles.push("back-office");

if (user.email === convention.signatories.establishmentRepresentative.email)
roles.push("establishment-representative");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("UpdateConventionStatus", () => {
"beneficiary-current-employer",
"counsellor",
"validator",
"backOffice",
"back-office",
],
allowedInclusionConnectedUsers: [
"icUserWithRoleCounsellor",
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("UpdateConventionStatus", () => {
"beneficiary-current-employer",
"counsellor",
"validator",
"backOffice",
"back-office",
],
allowedInclusionConnectedUsers: [
"icUserWithRoleCounsellor",
Expand Down Expand Up @@ -452,7 +452,7 @@ describe("UpdateConventionStatus", () => {
},
expectedDomainTopic: "ConventionRejected",
updatedFields: { statusJustification: "my rejection justification" },
allowedMagicLinkRoles: ["backOffice", "validator", "counsellor"],
allowedMagicLinkRoles: ["back-office", "validator", "counsellor"],
allowedInclusionConnectedUsers: [
"icUserWithRoleValidator",
"icUserWithRoleCounsellor",
Expand All @@ -472,7 +472,7 @@ describe("UpdateConventionStatus", () => {
statusJustification: "my rejection justification",
conventionId: originalConventionId,
},
allowedMagicLinkRoles: ["backOffice", "validator", "counsellor"],
allowedMagicLinkRoles: ["back-office", "validator", "counsellor"],
allowedInclusionConnectedUsers: [
"icUserWithRoleValidator",
"icUserWithRoleCounsellor",
Expand All @@ -497,7 +497,7 @@ describe("UpdateConventionStatus", () => {
},
expectedDomainTopic: "ConventionCancelled",
updatedFields: { statusJustification: "Cancelled justification" },
allowedMagicLinkRoles: ["validator", "backOffice"],
allowedMagicLinkRoles: ["validator", "back-office"],
allowedInclusionConnectedUsers: [
"icUserWithRoleValidator",
"icUserWithRoleBackofficeAdmin",
Expand All @@ -511,7 +511,7 @@ describe("UpdateConventionStatus", () => {
statusJustification: "Cancelled justification",
conventionId: originalConventionId,
},
allowedMagicLinkRoles: ["validator", "backOffice"],
allowedMagicLinkRoles: ["validator", "back-office"],
allowedInclusionConnectedUsers: [
"icUserWithRoleValidator",
"icUserWithRoleBackofficeAdmin",
Expand All @@ -530,7 +530,7 @@ describe("UpdateConventionStatus", () => {
},
expectedDomainTopic: "ConventionDeprecated",
updatedFields: { statusJustification: "my deprecation justification" },
allowedMagicLinkRoles: ["backOffice", "validator", "counsellor"],
allowedMagicLinkRoles: ["back-office", "validator", "counsellor"],
allowedInclusionConnectedUsers: [
"icUserWithRoleCounsellor",
"icUserWithRoleValidator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class NotifyActorThatConventionNeedsModifications extends TransactionalUs
email: recipient,
now: this.timeGateway.now(),
// UGLY : need to rework, handling of JWT payloads
...(recipientRole === "backOffice"
...(recipientRole === "back-office"
? { sub: this.config.backofficeUsername }
: {}),
};
Expand Down Expand Up @@ -187,11 +187,11 @@ const requesterNameByRole = (
"establishment-representative": `${convention.signatories.establishmentRepresentative.firstName} ${convention.signatories.establishmentRepresentative.lastName} (le représentant légal de l'entreprise)`,
counsellor: agency.name,
validator: agency.name,
backOffice: "L'équipe Immersion Facilitée",
agencyAdmin: "Le responsable d'agence",
"back-office": "L'équipe Immersion Facilitée",
"agency-admin": "Le responsable d'agence",
"establishment-tutor": new Error(wrongRequesterUser),
"agency-viewer": new Error(wrongRequesterUser),
toReview: new Error(wrongRequesterUser),
"to-review": new Error(wrongRequesterUser),
};
return strategy[requesterRole];
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("NotifyActorThatConventionNeedsModifications", () => {
requesterName: agency.name,
},
{
requesterRole: "backOffice",
requesterRole: "back-office",
modifierRole: "beneficiary",
email: [convention.signatories.beneficiary.email],
requesterName: "L'équipe Immersion Facilitée",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class NotifyAllActorsOfFinalConventionValidation extends TransactionalUse
now: this.#timeGateway.now(),
exp: this.#timeGateway.now().getTime() + 1000 * 60 * 60 * 24 * 365, // 1 year
// UGLY : need to rework, handling of JWT payloads
...(role === "backOffice"
...(role === "back-office"
? { sub: this.#config.backofficeUsername }
: {}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class NotifyIcUserAgencyRightChanged extends TransactionalUseCase<
const user = await uow.userRepository.getById(params.userId);
if (!user) throw errors.user.notFound({ userId: params.userId });

if (!params.roles.includes("toReview"))
if (!params.roles.includes("to-review"))
await this.#saveNotificationAndRelatedEvent(uow, {
kind: "email",
templatedContent: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("SendEmailWhenAgencyIsActivated", () => {
},
agencyRights: [
{
roles: ["toReview"],
roles: ["to-review"],
agency,
isNotifiedByEmail: false,
},
Expand Down Expand Up @@ -151,7 +151,7 @@ describe("SendEmailWhenAgencyIsActivated", () => {
uow.userRepository.setInclusionConnectedUsers([icUser]);

await notifyIcUserAgencyRightChanged.execute({
roles: ["toReview"],
roles: ["to-review"],
agencyId: "agency-1",
userId: icUser.id,
isNotifiedByEmail: false,
Expand Down
Loading

0 comments on commit 191722e

Please sign in to comment.