Skip to content

Commit

Permalink
hotfix : Ne pas désactiver l'interrupteur Soumis à l'ADR lors de la d…
Browse files Browse the repository at this point in the history
…uplication d'un BSDD
  • Loading branch information
benoitguigal committed Nov 28, 2024
1 parent f4a7e71 commit c000ea9
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 117 deletions.
1 change: 1 addition & 0 deletions back/src/__tests__/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const formdata: Partial<Prisma.FormCreateInput> = {
wasteDetailsIsDangerous: true,
wasteDetailsName: "Divers",
wasteDetailsOnuCode: "2003",
wasteDetailsIsSubjectToADR: true,
wasteDetailsPackagingInfos: [{ type: "CITERNE", quantity: 1 }],
wasteDetailsPop: false,
wasteDetailsQuantity: 22.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Pick<Mutation, "duplicateForm">>(
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<Pick<Mutation, "duplicateForm">>(
DUPLICATE_FORM,
{
variables: {
id: form.id
}
}
);

const duplicatedForm = await prisma.form.findUniqueOrThrow({
where: {
id: data.duplicateForm.id
}
});

expect(duplicatedForm).toEqual(
expect.objectContaining({
wasteDetailsIsSubjectToADR
})
);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -609,6 +614,7 @@ describe("Mutation.markAsSealed", () => {
recipientCompanySiret: recipientCompany.siret,
wasteDetailsCode: "01 01 01",
wasteDetailsIsDangerous: false,
wasteDetailsIsSubjectToADR: false,
wasteDetailsOnuCode: null
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pick<Mutation, "signedByTransporter">>(
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<Pick<Mutation, "signedByTransporter">>(
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(
Expand Down Expand Up @@ -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<Mutation, "signedByTransporter">
>(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<Mutation, "signedByTransporter">
>(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");
Expand Down
4 changes: 3 additions & 1 deletion back/src/forms/resolvers/mutations/duplicateForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c000ea9

Please sign in to comment.