From 8c08afaa791b5dbae167edda70f84fb0eabfa131 Mon Sep 17 00:00:00 2001 From: celineung Date: Thu, 5 Dec 2024 10:32:53 +0100 Subject: [PATCH] fix send convention of allowed agency type to FT --- .../convention/ports/PoleEmploiGateway.ts | 4 +- ...dcastToFranceTravailOnConventionUpdates.ts | 6 +- ...nceTravailOnConventionUpdates.unit.test.ts | 237 +++++++++++------- 3 files changed, 152 insertions(+), 95 deletions(-) diff --git a/back/src/domains/convention/ports/PoleEmploiGateway.ts b/back/src/domains/convention/ports/PoleEmploiGateway.ts index 7ffa7d9933..297a9787fb 100644 --- a/back/src/domains/convention/ports/PoleEmploiGateway.ts +++ b/back/src/domains/convention/ports/PoleEmploiGateway.ts @@ -33,7 +33,9 @@ type ConventionStatusToPeStatus = typeof conventionStatusToPoleEmploiStatus; type PeConventionStatus = ConventionStatusToPeStatus[keyof ConventionStatusToPeStatus]; -type AgencyKindForPe = Exclude | "france-travail"; +export type AgencyKindForPe = + | Exclude + | "france-travail"; export type PoleEmploiConvention = { id: string; // id numérique sur 11 caractères diff --git a/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.ts b/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.ts index 8dddce0492..ad155a2c74 100644 --- a/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.ts +++ b/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.ts @@ -200,13 +200,13 @@ const shouldBroadcastToFranceTravail = ({ if ( featureFlags.enableBroadcastOfConseilDepartementalToFT.isActive && - isBroadcastToFranceTravailAllowedForKind("structure-IAE") + isBroadcastToFranceTravailAllowedForKind("conseil-departemental") ) return true; if ( - featureFlags.enableBroadcastOfConseilDepartementalToFT.isActive && - isBroadcastToFranceTravailAllowedForKind("conseil-departemental") + featureFlags.enableBroadcastOfCapEmploiToFT.isActive && + isBroadcastToFranceTravailAllowedForKind("cap-emploi") ) return true; diff --git a/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.unit.test.ts b/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.unit.test.ts index 61b63f6bdd..7461b96689 100644 --- a/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.unit.test.ts +++ b/back/src/domains/convention/use-cases/broadcast/BroadcastToFranceTravailOnConventionUpdates.unit.test.ts @@ -1,7 +1,9 @@ import { AgencyDtoBuilder, + AgencyKind, ConventionDtoBuilder, ConventionId, + FeatureFlags, expectObjectsToMatch, expectPromiseToFailWithError, expectToEqual, @@ -16,6 +18,7 @@ import { createInMemoryUow, } from "../../../core/unit-of-work/adapters/createInMemoryUow"; import { InMemoryPoleEmploiGateway } from "../../adapters/pole-emploi-gateway/InMemoryPoleEmploiGateway"; +import { AgencyKindForPe } from "../../ports/PoleEmploiGateway"; import { BroadcastToFranceTravailOnConventionUpdates } from "./BroadcastToFranceTravailOnConventionUpdates"; describe("Broadcasts events to France Travail", () => { @@ -283,113 +286,165 @@ describe("Broadcasts events to France Travail", () => { }); describe("sends also other type of Convention when corresponding feature flag is activated", () => { - const agencyMissionLocal = toAgencyWithRights( - new AgencyDtoBuilder() - .withId("mission-local-id") - .withKind("mission-locale") - .build(), - ); + const createAgencyAndLinkedConvention = (kind: AgencyKind) => { + const agency = toAgencyWithRights( + new AgencyDtoBuilder().withId(kind).withKind(kind).build(), + ); - const conventionLinkedToMissionLocal = new ConventionDtoBuilder() - .withId("33333333-3333-4000-3333-333333333333") - .withAgencyId(agencyMissionLocal.id) - .build(); + return { + agency, + convention: new ConventionDtoBuilder() + .withId("33333333-3333-4000-3333-333333333333") + .withAgencyId(agency.id) + .build(), + }; + }; - describe("when enableBroadcastOfMissionLocaleToFT feature flag is ACTIVE", () => { - it("broadcasts to france travail, even for convention linked to mission-local", async () => { - uow.agencyRepository.agencies = [agencyMissionLocal]; - uow.featureFlagRepository.featureFlags = { + describe.each([ + { + agencyKind: "mission-locale" as AgencyKindForPe, + featureFlag: { enableBroadcastOfMissionLocaleToFT: { kind: "boolean", isActive: true, }, - enableBroadcastOfCapEmploiToFT: { kind: "boolean", isActive: false }, + } as Partial, + ...createAgencyAndLinkedConvention("mission-locale"), + }, + { + agencyKind: "conseil-departemental" as AgencyKindForPe, + featureFlag: { enableBroadcastOfConseilDepartementalToFT: { kind: "boolean", - isActive: false, + isActive: true, }, - }; - await broadcastToFranceTravailOnConventionUpdates.execute({ - convention: conventionLinkedToMissionLocal, - }); - - expect(poleEmploiGateWay.notifications).toHaveLength(1); - expectObjectsToMatch(poleEmploiGateWay.notifications[0], { - siret: conventionLinkedToMissionLocal.siret, - typeAgence: "mission-locale", - }); - }); - - it("broadcast to france travail when convention is from an agency RefersTo (and the refered agency is mission-locale)", async () => { - uow.featureFlagRepository.featureFlags = { - enableBroadcastOfMissionLocaleToFT: { + } as Partial, + ...createAgencyAndLinkedConvention("conseil-departemental"), + }, + { + agencyKind: "cap-emploi" as AgencyKindForPe, + featureFlag: { + enableBroadcastOfCapEmploiToFT: { kind: "boolean", isActive: true, }, - }; - - const agencyWithRefersTo = toAgencyWithRights( - new AgencyDtoBuilder(peAgencyWithoutCounsellorsAndValidators) - .withId("agency-with-refers-to-id") - .withKind("autre") - .withRefersToAgencyInfo({ - refersToAgencyId: agencyMissionLocal.id, - refersToAgencyName: agencyMissionLocal.name, - }) - .build(), - ); - - const conventionLinkedToAgencyReferingToOther = - new ConventionDtoBuilder() - .withId("22222222-2222-4000-2222-222222222222") - .withAgencyId(agencyWithRefersTo.id) - .withStatus("ACCEPTED_BY_VALIDATOR") - .build(); - - uow.agencyRepository.agencies = [ - agencyMissionLocal, - agencyWithRefersTo, - ]; - - const externalId = "00000000001"; - uow.conventionExternalIdRepository.externalIdsByConventionId = { - [conventionLinkedToAgencyReferingToOther.id]: externalId, - }; - - await broadcastToFranceTravailOnConventionUpdates.execute({ - convention: conventionLinkedToAgencyReferingToOther, + } as Partial, + ...createAgencyAndLinkedConvention("cap-emploi"), + }, + ])( + "when enable $agencyKind feature flag is ACTIVE", + ({ agencyKind, featureFlag, agency, convention }) => { + it(`broadcasts to france travail, even for convention linked to ${agencyKind}`, async () => { + uow.agencyRepository.agencies = [agency]; + uow.featureFlagRepository.featureFlags = { + enableBroadcastOfMissionLocaleToFT: { + kind: "boolean", + isActive: false, + }, + enableBroadcastOfCapEmploiToFT: { + kind: "boolean", + isActive: false, + }, + enableBroadcastOfConseilDepartementalToFT: { + kind: "boolean", + isActive: false, + }, + ...featureFlag, + }; + await broadcastToFranceTravailOnConventionUpdates.execute({ + convention, + }); + + expect(poleEmploiGateWay.notifications).toHaveLength(1); + expectObjectsToMatch(poleEmploiGateWay.notifications[0], { + siret: convention.siret, + typeAgence: agencyKind, + }); }); - // Assert - expect(poleEmploiGateWay.notifications).toHaveLength(1); - expectObjectsToMatch(poleEmploiGateWay.notifications[0], { - id: externalId, - originalId: conventionLinkedToAgencyReferingToOther.id, - statut: "DEMANDE_VALIDÉE", + it(`broadcast to france travail when convention is from an agency RefersTo (and the refered agency is ${agencyKind})`, async () => { + uow.featureFlagRepository.featureFlags = featureFlag; + + const agencyWithRefersTo = toAgencyWithRights( + new AgencyDtoBuilder(peAgencyWithoutCounsellorsAndValidators) + .withId("agency-with-refers-to-id") + .withKind("autre") + .withRefersToAgencyInfo({ + refersToAgencyId: agency.id, + refersToAgencyName: agency.name, + }) + .build(), + ); + + const conventionLinkedToAgencyReferingToOther = + new ConventionDtoBuilder() + .withId("22222222-2222-4000-2222-222222222222") + .withAgencyId(agencyWithRefersTo.id) + .withStatus("ACCEPTED_BY_VALIDATOR") + .build(); + + uow.agencyRepository.agencies = [agency, agencyWithRefersTo]; + + const externalId = "00000000001"; + uow.conventionExternalIdRepository.externalIdsByConventionId = { + [conventionLinkedToAgencyReferingToOther.id]: externalId, + }; + + await broadcastToFranceTravailOnConventionUpdates.execute({ + convention: conventionLinkedToAgencyReferingToOther, + }); + + // Assert + expect(poleEmploiGateWay.notifications).toHaveLength(1); + expectObjectsToMatch(poleEmploiGateWay.notifications[0], { + id: externalId, + originalId: conventionLinkedToAgencyReferingToOther.id, + statut: "DEMANDE_VALIDÉE", + }); }); - }); - }); + }, + ); - describe("when enableBroadcastOfMissionLocaleToFT feature flag is OFF", () => { - it("does NOT broadcasts to france travail, for mission-local", async () => { - uow.agencyRepository.agencies = [agencyMissionLocal]; - uow.featureFlagRepository.featureFlags = { - enableBroadcastOfMissionLocaleToFT: { - kind: "boolean", - isActive: false, - }, - enableBroadcastOfCapEmploiToFT: { kind: "boolean", isActive: false }, - enableBroadcastOfConseilDepartementalToFT: { - kind: "boolean", - isActive: false, - }, - }; - await broadcastToFranceTravailOnConventionUpdates.execute({ - convention: conventionLinkedToMissionLocal, + describe.each([ + { + agencyKind: "mission-locale" as AgencyKindForPe, + ...createAgencyAndLinkedConvention("mission-locale"), + }, + { + agencyKind: "conseil-departemental" as AgencyKindForPe, + ...createAgencyAndLinkedConvention("conseil-departemental"), + }, + { + agencyKind: "cap-emploi" as AgencyKindForPe, + ...createAgencyAndLinkedConvention("cap-emploi"), + }, + ])( + "when $agencyKind feature flag is OFF", + ({ agencyKind, agency, convention }) => { + it(`does NOT broadcasts to france travail, for ${agencyKind}`, async () => { + uow.agencyRepository.agencies = [agency]; + uow.featureFlagRepository.featureFlags = { + enableBroadcastOfMissionLocaleToFT: { + kind: "boolean", + isActive: false, + }, + enableBroadcastOfCapEmploiToFT: { + kind: "boolean", + isActive: false, + }, + enableBroadcastOfConseilDepartementalToFT: { + kind: "boolean", + isActive: false, + }, + }; + + await broadcastToFranceTravailOnConventionUpdates.execute({ + convention: convention, + }); + + expect(poleEmploiGateWay.notifications).toHaveLength(0); }); - - expect(poleEmploiGateWay.notifications).toHaveLength(0); - }); - }); + }, + ); }); });