From c000ea9988d720dd87f61e9749358b93467d6014 Mon Sep 17 00:00:00 2001 From: Benoit Guigal Date: Thu, 28 Nov 2024 09:47:22 +0100 Subject: [PATCH] =?UTF-8?q?hotfix=20:=20Ne=20pas=20d=C3=A9sactiver=20l'int?= =?UTF-8?q?errupteur=20Soumis=20=C3=A0=20l'ADR=20lors=20de=20la=20duplicat?= =?UTF-8?q?ion=20d'un=20BSDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/src/__tests__/factories.ts | 1 + .../__tests__/duplicateForm.integration.ts | 79 +++++++- .../__tests__/markAsSealed.integration.ts | 66 ++++--- .../signedByTransporter.integration.ts | 178 +++++++++--------- .../resolvers/mutations/duplicateForm.ts | 4 +- 5 files changed, 211 insertions(+), 117 deletions(-) diff --git a/back/src/__tests__/factories.ts b/back/src/__tests__/factories.ts index 8cf7a00bba..a6b0a8dc1d 100644 --- a/back/src/__tests__/factories.ts +++ b/back/src/__tests__/factories.ts @@ -335,6 +335,7 @@ const formdata: Partial = { wasteDetailsIsDangerous: true, wasteDetailsName: "Divers", wasteDetailsOnuCode: "2003", + wasteDetailsIsSubjectToADR: true, wasteDetailsPackagingInfos: [{ type: "CITERNE", quantity: 1 }], wasteDetailsPop: false, wasteDetailsQuantity: 22.5, diff --git a/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts b/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts index a8a80e1802..04761f06f6 100644 --- a/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts @@ -154,8 +154,7 @@ describe("Mutation.duplicateForm", () => { it("should duplicate a form %s", async () => { const { form, emitter } = await createForm({ ecoOrganismeName: "COREPILE", - ecoOrganismeSiret: siretify(1), - wasteDetailsIsSubjectToADR: true + ecoOrganismeSiret: siretify(1) }); const { @@ -1259,4 +1258,80 @@ describe("Mutation.duplicateForm", () => { ); } ); + + it.each([true, false, null])( + "should set `wasteDetailsIsSubjectToADR=true` when waste is dangerous " + + "and wasteDetailsIsSubjectToADR is %p on the BSDD being duplicated", + async wasteDetailsIsSubjectToADR => { + const { user, company } = await userWithCompanyFactory(UserRole.MEMBER); + const form = await formFactory({ + ownerId: user.id, + opt: { + emitterCompanySiret: company.siret, + wasteDetailsIsDangerous: true, + wasteDetailsIsSubjectToADR + } + }); + + const { mutate } = makeClient(user); + const { data } = await mutate>( + DUPLICATE_FORM, + { + variables: { + id: form.id + } + } + ); + + const duplicatedForm = await prisma.form.findUniqueOrThrow({ + where: { + id: data.duplicateForm.id + } + }); + + expect(duplicatedForm).toEqual( + expect.objectContaining({ + wasteDetailsIsSubjectToADR: true + }) + ); + } + ); + + it.each([true, false, null])( + "should keep existing wasteDetailsIsSubjectToADR when" + + " wasteDetailsIsSubjectToADR is %p and waste is not dangerous", + async wasteDetailsIsSubjectToADR => { + const { user, company } = await userWithCompanyFactory(UserRole.MEMBER); + const form = await formFactory({ + ownerId: user.id, + opt: { + emitterCompanySiret: company.siret, + wasteDetailsIsDangerous: false, + wasteDetailsIsSubjectToADR + } + }); + + const { mutate } = makeClient(user); + const { data } = await mutate>( + DUPLICATE_FORM, + { + variables: { + id: form.id + } + } + ); + + const duplicatedForm = await prisma.form.findUniqueOrThrow({ + where: { + id: data.duplicateForm.id + } + }); + + expect(duplicatedForm).toEqual( + expect.objectContaining({ + wasteDetailsIsSubjectToADR + }) + ); + } + ); }); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts index 48a947f3ce..f68864acff 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts @@ -563,38 +563,43 @@ describe("Mutation.markAsSealed", () => { } ); - it("should be required to provide onuCode for dangerous wastes", async () => { - const { user, company: emitterCompany } = await userWithCompanyFactory( - "MEMBER" - ); - const recipientCompany = await destinationFactory(); - const form = await formFactory({ - ownerId: user.id, - opt: { - status: "DRAFT", - emitterCompanySiret: emitterCompany.siret, - recipientCompanySiret: recipientCompany.siret, - wasteDetailsCode: "05 01 04*", - wasteDetailsOnuCode: null - } - }); + it( + "should be required to provide onuCode for dangerous wastes" + + " when `wasteDetailsIsSubjectToADR` is not speified ", + async () => { + const { user, company: emitterCompany } = await userWithCompanyFactory( + "MEMBER" + ); + const recipientCompany = await destinationFactory(); + const form = await formFactory({ + ownerId: user.id, + opt: { + status: "DRAFT", + emitterCompanySiret: emitterCompany.siret, + recipientCompanySiret: recipientCompany.siret, + wasteDetailsCode: "05 01 04*", + wasteDetailsOnuCode: null, + wasteDetailsIsSubjectToADR: null + } + }); - const { mutate } = makeClient(user); + const { mutate } = makeClient(user); - const { errors } = await mutate(MARK_AS_SEALED, { - variables: { - id: form.id - } - }); - expect(errors).toEqual([ - expect.objectContaining({ - message: [ - "Erreur, impossible de valider le bordereau car des champs obligatoires ne sont pas renseignés.", - `Erreur(s): La mention ADR est obligatoire pour les déchets dangereux. Merci d'indiquer "non soumis" si nécessaire.` - ].join("\n") - }) - ]); - }); + const { errors } = await mutate(MARK_AS_SEALED, { + variables: { + id: form.id + } + }); + expect(errors).toEqual([ + expect.objectContaining({ + message: [ + "Erreur, impossible de valider le bordereau car des champs obligatoires ne sont pas renseignés.", + `Erreur(s): La mention ADR est obligatoire pour les déchets dangereux. Merci d'indiquer "non soumis" si nécessaire.` + ].join("\n") + }) + ]); + } + ); it("should be optional to provide onuCode for non-dangerous wastes", async () => { const { user, company: emitterCompany } = await userWithCompanyFactory( @@ -609,6 +614,7 @@ describe("Mutation.markAsSealed", () => { recipientCompanySiret: recipientCompany.siret, wasteDetailsCode: "01 01 01", wasteDetailsIsDangerous: false, + wasteDetailsIsSubjectToADR: false, wasteDetailsOnuCode: null } }); diff --git a/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts b/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts index 4e5b331016..9fed3a39ea 100644 --- a/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts @@ -196,58 +196,63 @@ describe("Mutation.signedByTransporter", () => { ); }); - it("should return an error if onuCode is provided empty for a dangerous waste", async () => { - const { user, company: transporter } = await userWithCompanyFactory( - "ADMIN" - ); - await transporterReceiptFactory({ company: transporter }); + it( + "should return an error if onuCode is provided empty for a dangerous waste " + + "and wasteDetailsIsSubjectToADR is not specified", + async () => { + const { user, company: transporter } = await userWithCompanyFactory( + "ADMIN" + ); + await transporterReceiptFactory({ company: transporter }); - const emitter = await companyFactory(); - const form = await formFactory({ - ownerId: user.id, - opt: { - sentAt: null, - status: "SEALED", - wasteDetailsCode: "01 03 04*", - emitterCompanySiret: emitter.siret, - transporters: { - create: { - transporterCompanySiret: transporter.siret, - number: 1 + const emitter = await companyFactory(); + const form = await formFactory({ + ownerId: user.id, + opt: { + sentAt: null, + status: "SEALED", + wasteDetailsCode: "01 03 04*", + wasteDetailsIsSubjectToADR: null, + emitterCompanySiret: emitter.siret, + transporters: { + create: { + transporterCompanySiret: transporter.siret, + number: 1 + } } } - } - }); + }); - const { mutate } = makeClient(user); - const { errors } = await mutate>( - SIGNED_BY_TRANSPORTER, - { - variables: { - id: form.id, - signingInfo: { - sentAt: "2018-12-11T00:00:00.000Z", - signedByTransporter: true, - securityCode: emitter.securityCode, - sentBy: "Roger Lapince", - signedByProducer: true, - packagingInfos: form.wasteDetailsPackagingInfos, - quantity: form.wasteDetailsQuantity?.toNumber(), - onuCode: "" + const { mutate } = makeClient(user); + const { errors } = await mutate>( + SIGNED_BY_TRANSPORTER, + { + variables: { + id: form.id, + signingInfo: { + sentAt: "2018-12-11T00:00:00.000Z", + signedByTransporter: true, + securityCode: emitter.securityCode, + sentBy: "Roger Lapince", + signedByProducer: true, + packagingInfos: form.wasteDetailsPackagingInfos, + quantity: form.wasteDetailsQuantity?.toNumber(), + onuCode: "" + } } } - } - ); + ); - expect(errors).toEqual([ - expect.objectContaining({ - message: `La mention ADR est obligatoire pour les déchets dangereux. Merci d'indiquer "non soumis" si nécessaire.`, - extensions: expect.objectContaining({ - code: ErrorCode.BAD_USER_INPUT + expect(errors).toEqual([ + expect.objectContaining({ + message: `La mention ADR est obligatoire pour les déchets dangereux. Merci d'indiquer "non soumis" si nécessaire.`, + extensions: expect.objectContaining({ + code: ErrorCode.BAD_USER_INPUT + }) }) - }) - ]); - }); + ]); + } + ); it("should return an error if transporter receipt is missing", async () => { const { user, company: transporter } = await userWithCompanyFactory( @@ -302,52 +307,57 @@ describe("Mutation.signedByTransporter", () => { ]); }); - it("should not return an error if onuCode is provided empty for a non-dangerous waste", async () => { - const { user, company: transporter } = await userWithCompanyFactory( - "ADMIN" - ); - await transporterReceiptFactory({ company: transporter }); + it( + "should not return an error if onuCode is provided empty for a non-dangerous waste " + + "and wasteDetailsIsSubjectToADR is not specified", + async () => { + const { user, company: transporter } = await userWithCompanyFactory( + "ADMIN" + ); + await transporterReceiptFactory({ company: transporter }); - const emitter = await companyFactory(); - const form = await formFactory({ - ownerId: user.id, - opt: { - sentAt: null, - status: "SEALED", - wasteDetailsCode: "01 01 01", - wasteDetailsIsDangerous: false, - emitterCompanySiret: emitter.siret, - transporters: { - create: { - transporterCompanySiret: transporter.siret, - number: 1 + const emitter = await companyFactory(); + const form = await formFactory({ + ownerId: user.id, + opt: { + sentAt: null, + status: "SEALED", + wasteDetailsCode: "01 01 01", + wasteDetailsIsDangerous: false, + wasteDetailsIsSubjectToADR: null, + emitterCompanySiret: emitter.siret, + transporters: { + create: { + transporterCompanySiret: transporter.siret, + number: 1 + } } } - } - }); + }); - const { mutate } = makeClient(user); - const { data, errors } = await mutate< - Pick - >(SIGNED_BY_TRANSPORTER, { - variables: { - id: form.id, - signingInfo: { - sentAt: "2018-12-11T00:00:00.000Z", - signedByTransporter: true, - securityCode: emitter.securityCode, - sentBy: "Roger Lapince", - signedByProducer: true, - packagingInfos: form.wasteDetailsPackagingInfos, - quantity: form.wasteDetailsQuantity?.toNumber(), - onuCode: "" + const { mutate } = makeClient(user); + const { data, errors } = await mutate< + Pick + >(SIGNED_BY_TRANSPORTER, { + variables: { + id: form.id, + signingInfo: { + sentAt: "2018-12-11T00:00:00.000Z", + signedByTransporter: true, + securityCode: emitter.securityCode, + sentBy: "Roger Lapince", + signedByProducer: true, + packagingInfos: form.wasteDetailsPackagingInfos, + quantity: form.wasteDetailsQuantity?.toNumber(), + onuCode: "" + } } - } - }); + }); - expect(errors).toBe(undefined); - expect(data.signedByTransporter.status).toBe("SENT"); - }); + expect(errors).toBe(undefined); + expect(data.signedByTransporter.status).toBe("SENT"); + } + ); it("should fail if wrong security code", async () => { const { user, company } = await userWithCompanyFactory("ADMIN"); diff --git a/back/src/forms/resolvers/mutations/duplicateForm.ts b/back/src/forms/resolvers/mutations/duplicateForm.ts index 70a1ddb44b..fea6abc86e 100644 --- a/back/src/forms/resolvers/mutations/duplicateForm.ts +++ b/back/src/forms/resolvers/mutations/duplicateForm.ts @@ -127,7 +127,9 @@ async function getDuplicateFormInput( wasteDetailsName: form.wasteDetailsName, wasteDetailsConsistence: form.wasteDetailsConsistence, wasteDetailsSampleNumber: form.wasteDetailsSampleNumber, - wasteDetailsIsSubjectToADR: form.wasteDetailsIsSubjectToADR, + wasteDetailsIsSubjectToADR: form.wasteDetailsIsDangerous + ? true + : form.wasteDetailsIsSubjectToADR, traderCompanyName: trader?.name ?? form.traderCompanyName, traderCompanySiret: form.traderCompanySiret, traderCompanyAddress: trader?.address ?? form.traderCompanyAddress,