Skip to content

Commit

Permalink
Fixes annexe 1 CTA (#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornifex authored Oct 17, 2024
1 parent b89d63f commit 8a1c98c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions front/src/Apps/Dashboard/bsdMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const mapBsdd = (bsdd: Form): BsdDisplay => {
ecoOrganisme: bsdd.ecoOrganisme,
broker: bsdd.broker,
trader: bsdd.trader,
intermediaries: bsdd.intermediaries,
updatedAt: bsdd.stateSummary?.lastActionOn,
emittedByEcoOrganisme: bsdd.emittedByEcoOrganisme,
grouping: bsdd.grouping,
Expand Down
17 changes: 17 additions & 0 deletions front/src/Apps/Dashboard/dashboardServices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,27 @@ describe("dashboardServices", () => {
transporter: { company: { siret: "2" } },
broker: { company: { siret: "4" } },
trader: { company: { siret: "5" } },
intermediaries: [{ siret: "6" }],
destination: { company: { siret: "3" } },
ecoOrganisme: { siret: "2" }
} as BsdDisplay;

it("should return true if testing for Intermediary, strict", () => {
const currentSiret = "6";
const result = isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Intermediary }
]);
expect(result).toBe(true);
});

it("should return false if testing for Broker with wrong siret, strict", () => {
const currentSiret = "6";
const result = isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Broker }
]);
expect(result).toBe(false);
});

it("should return true if testing for EcoOrganisme, non-strict", () => {
const currentSiret = "2";
const result = isSiretActorForBsd(bsd, currentSiret, [
Expand Down
36 changes: 24 additions & 12 deletions front/src/Apps/Dashboard/dashboardServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ export const isSiretActorForBsd = (
: actorTypes
.map(({ type, strict = false }) => {
return actorTypesForSiret.includes(type) && strict
? actorTypesForSiret.length === 1
: true;
? actorTypesForSiret.includes(type) &&
actorTypesForSiret.length === 1
: actorTypesForSiret.includes(type);
})
.reduce((acc, curr) => acc && curr, true);
};
Expand Down Expand Up @@ -592,7 +593,11 @@ export const getSealedBtnLabel = (
(permissions.includes(UserPermission.BsdCanSignEmission) ||
permissions.includes(UserPermission.BsdCanSignTransport))
) {
if (isAppendix1(bsd) && canAddAppendix1(bsd)) {
if (
isAppendix1(bsd) &&
canAddAppendix1(bsd) &&
hasAppendix1Cta(bsd, currentSiret)
) {
return AJOUTER_ANNEXE_1;
}

Expand Down Expand Up @@ -678,6 +683,7 @@ export const getSentBtnLabel = (
if (
isAppendix1(bsd) &&
canAddAppendix1(bsd) &&
hasAppendix1Cta(bsd, currentSiret) &&
permissions.includes(UserPermission.BsdCanUpdate)
) {
return AJOUTER_ANNEXE_1;
Expand Down Expand Up @@ -1502,20 +1508,26 @@ export const hasAppendix1Cta = (
bsd: BsdDisplay,
currentSiret: string
): boolean => {
const isBroker = isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Broker, strict: true }
]);

const isIntermediary = isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Intermediary, strict: true }
]);

const isTrader = isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Trader, strict: true }
]);

return (
bsd.type === BsdType.Bsdd &&
bsd?.emitterType === EmitterType.Appendix1 &&
(BsdStatusCode.Sealed === bsd.status ||
BsdStatusCode.Sent === bsd.status) &&
!isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Broker, strict: true }
]) &&
!isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Intermediary, strict: true }
]) &&
!isSiretActorForBsd(bsd, currentSiret, [
{ type: ActorType.Trader, strict: true }
])
!isBroker &&
!isIntermediary &&
!isTrader
);
};

Expand Down
12 changes: 12 additions & 0 deletions front/src/Apps/common/queries/fragments/bsdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ export const dashboardFormFragment = gql`
}
currentTransporterSiret
nextTransporterSiret
intermediaries {
...CompanyFragment
}
trader {
...TraderFragment
}
broker {
...BrokerFragment
}
metadata {
latestRevision {
id
Expand All @@ -583,4 +592,7 @@ export const dashboardFormFragment = gql`
}
}
}
${traderFragment}
${companyFragment}
${brokerFragment}
`;

0 comments on commit 8a1c98c

Please sign in to comment.