From 3d334f14477cc0e501ee00c7da3c8aa5c1d008a4 Mon Sep 17 00:00:00 2001 From: clement-duport Date: Tue, 6 Jun 2023 18:31:57 +0200 Subject: [PATCH] fix review fix review second part --- .../src/adapters/primary/subscribeToEvents.ts | 4 +--- .../UpdateConventionStatus.testHelpers.ts | 1 + .../useCases/UpdateConventionStatus.ts | 2 +- .../UpdateConventionStatus.unit.test.ts | 19 +++++++++++++++++++ ...tifyAllActorsThatConventionIsDeprecated.ts | 18 ++++++++++-------- back/src/domain/core/eventBus/events.ts | 2 +- .../components/admin/ConventionValidation.tsx | 2 +- .../convention/VerificationActionButton.tsx | 4 ++-- .../convention/conventionStatusTransitions.ts | 3 ++- shared/src/email/emailTemplatesByName.ts | 2 +- 10 files changed, 39 insertions(+), 18 deletions(-) diff --git a/back/src/adapters/primary/subscribeToEvents.ts b/back/src/adapters/primary/subscribeToEvents.ts index 34f981d680..7cb6fc05b0 100644 --- a/back/src/adapters/primary/subscribeToEvents.ts +++ b/back/src/adapters/primary/subscribeToEvents.ts @@ -77,9 +77,7 @@ const getUseCasesByTopics = ( ImmersionApplicationCancelled: [ useCases.broadcastToPoleEmploiOnConventionUpdates, ], - ImmersionApplicationDeprecated: [ - useCases.notifyAllActorsThatConventionIsDeprecated, - ], + ConventionDeprecated: [useCases.notifyAllActorsThatConventionIsDeprecated], ConventionReminderRequired: [useCases.notifyConventionReminder], // Establishment form related diff --git a/back/src/domain/convention/useCases/UpdateConventionStatus.testHelpers.ts b/back/src/domain/convention/useCases/UpdateConventionStatus.testHelpers.ts index d88aa54ae9..74de02b73c 100644 --- a/back/src/domain/convention/useCases/UpdateConventionStatus.testHelpers.ts +++ b/back/src/domain/convention/useCases/UpdateConventionStatus.testHelpers.ts @@ -44,6 +44,7 @@ type ConventionDomainTopic = ExtractFromDomainTopics< | "ImmersionApplicationRejected" | "ImmersionApplicationRequiresModification" | "ImmersionApplicationCancelled" + | "ConventionDeprecated" > | null; // null is used to indicate that no domain event should be sent type SetupInitialStateParams = { diff --git a/back/src/domain/convention/useCases/UpdateConventionStatus.ts b/back/src/domain/convention/useCases/UpdateConventionStatus.ts index 74926fa3e0..59f5a915a8 100644 --- a/back/src/domain/convention/useCases/UpdateConventionStatus.ts +++ b/back/src/domain/convention/useCases/UpdateConventionStatus.ts @@ -32,7 +32,7 @@ const domainTopicByTargetStatusMap: Record< REJECTED: "ImmersionApplicationRejected", CANCELLED: "ImmersionApplicationCancelled", DRAFT: "ImmersionApplicationRequiresModification", - DEPRECATED: "ImmersionApplicationDeprecated", + DEPRECATED: "ConventionDeprecated", }; type UpdateConventionStatusPayload = { diff --git a/back/src/domain/convention/useCases/UpdateConventionStatus.unit.test.ts b/back/src/domain/convention/useCases/UpdateConventionStatus.unit.test.ts index acce325d6f..4d697879c8 100644 --- a/back/src/domain/convention/useCases/UpdateConventionStatus.unit.test.ts +++ b/back/src/domain/convention/useCases/UpdateConventionStatus.unit.test.ts @@ -213,6 +213,25 @@ describe("UpdateConventionStatus", () => { }); }); + describe("* -> DEPRECATED transition", () => { + testForAllRolesAndInitialStatusCases({ + updateStatusParams: { + status: "DEPRECATED", + statusJustification: "my deprecation justification", + }, + expectedDomainTopic: "ConventionDeprecated", + updatedFields: { statusJustification: "my deprecation justification" }, + allowedRoles: ["backOffice", "validator", "counsellor"], + allowedInitialStatuses: [ + "PARTIALLY_SIGNED", + "READY_TO_SIGN", + "IN_REVIEW", + "ACCEPTED_BY_COUNSELLOR", + "DRAFT", + ], + }); + }); + it("fails for unknown application ids", async () => { const { updateConventionStatus, conventionRepository } = await setupInitialState({ initialStatus: "IN_REVIEW" }); diff --git a/back/src/domain/convention/useCases/notifications/NotifyAllActorsThatConventionIsDeprecated.ts b/back/src/domain/convention/useCases/notifications/NotifyAllActorsThatConventionIsDeprecated.ts index 6ae0168449..640423ac01 100644 --- a/back/src/domain/convention/useCases/notifications/NotifyAllActorsThatConventionIsDeprecated.ts +++ b/back/src/domain/convention/useCases/notifications/NotifyAllActorsThatConventionIsDeprecated.ts @@ -1,3 +1,4 @@ +import { uniq } from "ramda"; import { ConventionDto, conventionSchema } from "shared"; import { UnitOfWork, @@ -34,17 +35,14 @@ export class NotifyAllActorsThatConventionIsDeprecated extends TransactionalUseC beneficiaryRepresentative, } = convention.signatories; - const recipients = [ + const recipients = uniq([ beneficiary.email, establishmentRepresentative.email, ...agency.counsellorEmails, ...agency.validatorEmails, - ]; - - if (beneficiaryCurrentEmployer && beneficiaryCurrentEmployer.email) - recipients.push(beneficiaryCurrentEmployer.email); - if (beneficiaryRepresentative && beneficiaryRepresentative.email) - recipients.push(beneficiaryRepresentative.email); + ...(beneficiaryCurrentEmployer ? [beneficiaryCurrentEmployer.email] : []), + ...(beneficiaryRepresentative ? [beneficiaryRepresentative.email] : []), + ]); await this.saveNotificationAndRelatedEvent(uow, { kind: "email", @@ -62,7 +60,11 @@ export class NotifyAllActorsThatConventionIsDeprecated extends TransactionalUseC immersionProfession: convention.immersionAppellation.appellationLabel, }, }, - followedIds: {}, + followedIds: { + conventionId: convention.id, + agencyId: convention.agencyId, + establishmentSiret: convention.siret, + }, }); } } diff --git a/back/src/domain/core/eventBus/events.ts b/back/src/domain/core/eventBus/events.ts index f1a0c29747..4549887d14 100644 --- a/back/src/domain/core/eventBus/events.ts +++ b/back/src/domain/core/eventBus/events.ts @@ -62,7 +62,7 @@ export type DomainEvent = | GenericEvent<"ImmersionApplicationRejected", ConventionDto> | GenericEvent<"ImmersionApplicationCancelled", ConventionDto> | GenericEvent<"ImmersionApplicationRequiresModification", ConventionRequiresModificationPayload> - | GenericEvent<"ImmersionApplicationDeprecated", ConventionDto> + | GenericEvent<"ConventionDeprecated", ConventionDto> // MAGIC LINK RENEWAL | GenericEvent<"MagicLinkRenewalRequested", RenewMagicLinkPayload> diff --git a/front/src/app/components/admin/ConventionValidation.tsx b/front/src/app/components/admin/ConventionValidation.tsx index 9cfc76aba3..18ee22f8da 100644 --- a/front/src/app/components/admin/ConventionValidation.tsx +++ b/front/src/app/components/admin/ConventionValidation.tsx @@ -23,7 +23,7 @@ const labelByStatus: Record = { PARTIALLY_SIGNED: "[✍️ Partiellement signée]", READY_TO_SIGN: "[📄 En cours de signature]", REJECTED: "[❌ DEMANDE REJETÉE]", - DEPRECATED: "[DEMANDE OBSOLÈTE]", + DEPRECATED: "[❌ DEMANDE OBSOLÈTE]", }; export interface ConventionValidationProps { diff --git a/front/src/app/components/forms/convention/VerificationActionButton.tsx b/front/src/app/components/forms/convention/VerificationActionButton.tsx index ca0dbfdec2..baaeff93d1 100644 --- a/front/src/app/components/forms/convention/VerificationActionButton.tsx +++ b/front/src/app/components/forms/convention/VerificationActionButton.tsx @@ -263,8 +263,8 @@ const JustificationModalContent = ({ const inputLabelByStatus: Record = { DRAFT: "Précisez la raison et la modification nécessaire", REJECTED: "Pourquoi l'immersion est-elle refusée ?", - CANCELLED: "Pourquoi souhaitez-vous annuler cette convention?", - DEPRECATED: "Pourquoi l'immersion est-elle obsolète", + CANCELLED: "Pourquoi souhaitez-vous annuler cette convention ?", + DEPRECATED: "Pourquoi l'immersion est-elle obsolète ?", }; const confirmByStatus: Record = { diff --git a/shared/src/convention/conventionStatusTransitions.ts b/shared/src/convention/conventionStatusTransitions.ts index 9fab885d47..b89f61de5a 100644 --- a/shared/src/convention/conventionStatusTransitions.ts +++ b/shared/src/convention/conventionStatusTransitions.ts @@ -82,7 +82,8 @@ export const statusTransitionConfigs: Record< "IN_REVIEW", "PARTIALLY_SIGNED", "READY_TO_SIGN", + "DRAFT", ], - validRoles: ["backOffice"], + validRoles: ["counsellor", "validator", "backOffice"], }, }; diff --git a/shared/src/email/emailTemplatesByName.ts b/shared/src/email/emailTemplatesByName.ts index e68ee17d3c..d60380f9d2 100644 --- a/shared/src/email/emailTemplatesByName.ts +++ b/shared/src/email/emailTemplatesByName.ts @@ -1194,7 +1194,7 @@ export const emailTemplatesByName = Bien cordialement, `, - subContent: defaultSignature("immersion"), + subContent: defaultSignature(internshipKind), }), }, });