Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
fix review second part
  • Loading branch information
clement-duport committed Jun 7, 2023
1 parent 10f94d8 commit 3d334f1
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 18 deletions.
4 changes: 1 addition & 3 deletions back/src/adapters/primary/subscribeToEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ const getUseCasesByTopics = (
ImmersionApplicationCancelled: [
useCases.broadcastToPoleEmploiOnConventionUpdates,
],
ImmersionApplicationDeprecated: [
useCases.notifyAllActorsThatConventionIsDeprecated,
],
ConventionDeprecated: [useCases.notifyAllActorsThatConventionIsDeprecated],
ConventionReminderRequired: [useCases.notifyConventionReminder],

// Establishment form related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const domainTopicByTargetStatusMap: Record<
REJECTED: "ImmersionApplicationRejected",
CANCELLED: "ImmersionApplicationCancelled",
DRAFT: "ImmersionApplicationRequiresModification",
DEPRECATED: "ImmersionApplicationDeprecated",
DEPRECATED: "ConventionDeprecated",
};

type UpdateConventionStatusPayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { uniq } from "ramda";
import { ConventionDto, conventionSchema } from "shared";
import {
UnitOfWork,
Expand Down Expand Up @@ -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",
Expand All @@ -62,7 +60,11 @@ export class NotifyAllActorsThatConventionIsDeprecated extends TransactionalUseC
immersionProfession: convention.immersionAppellation.appellationLabel,
},
},
followedIds: {},
followedIds: {
conventionId: convention.id,
agencyId: convention.agencyId,
establishmentSiret: convention.siret,
},
});
}
}
2 changes: 1 addition & 1 deletion back/src/domain/core/eventBus/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion front/src/app/components/admin/ConventionValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const labelByStatus: Record<ConventionStatus, string> = {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ const JustificationModalContent = ({
const inputLabelByStatus: Record<ConventionStatusWithJustification, string> = {
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<ConventionStatusWithJustification, string> = {
Expand Down
3 changes: 2 additions & 1 deletion shared/src/convention/conventionStatusTransitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const statusTransitionConfigs: Record<
"IN_REVIEW",
"PARTIALLY_SIGNED",
"READY_TO_SIGN",
"DRAFT",
],
validRoles: ["backOffice"],
validRoles: ["counsellor", "validator", "backOffice"],
},
};
2 changes: 1 addition & 1 deletion shared/src/email/emailTemplatesByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ export const emailTemplatesByName =
Bien cordialement,
`,
subContent: defaultSignature("immersion"),
subContent: defaultSignature(internshipKind),
}),
},
});

0 comments on commit 3d334f1

Please sign in to comment.