Skip to content

Commit

Permalink
Correction validation des plaques sur le bsdd multimodal (#3978)
Browse files Browse the repository at this point in the history
  • Loading branch information
providenz authored Feb 17, 2025
2 parents d0f0d45 + 5d74452 commit 3f3dcf0
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 4 deletions.
2 changes: 1 addition & 1 deletion back/src/bsvhu/validation/refinements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const v20241201 = new Date(
process.env.OVERRIDE_V20241201 || "2024-12-18T00:00:00.000"
);

// Date de la MAJ 2025.01.1 qui modifie les règles de validation du mode de transport, des palques d'immatriculations et la quantité transportée
// Date de la MAJ 2025.01.1 qui modifie les règles de validation du mode de transport, des plaques d'immatriculations et la quantité transportée
export const v20250101 = new Date(
process.env.OVERRIDE_V20250101 || "2025-01-15T00:00:00.000"
);
Expand Down
129 changes: 127 additions & 2 deletions back/src/forms/resolvers/mutations/__tests__/updateForm.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5048,11 +5048,12 @@ describe("Mutation.updateForm", () => {
companyTypes: [CompanyType.WASTEPROCESSOR],
wasteProcessorTypes: [WasteProcessorType.DANGEROUS_WASTES_INCINERATION]
});
// Create a form that has already been received
// Create a form that has already been sent
const form = await formFactory({
ownerId: emitter.user.id,
opt: {
status: Status.SENT,

emittedAt: new Date(),
takenOverAt: new Date(),
emitterCompanySiret: emitter.company.siret,
Expand Down Expand Up @@ -5098,7 +5099,7 @@ describe("Mutation.updateForm", () => {
const transporter1 = await userWithCompanyFactory("MEMBER");
const transporter2 = await userWithCompanyFactory("MEMBER");

// Create a form that has already been received
// Create a form that has already been sent
const form = await formFactory({
ownerId: emitter.user.id,
opt: {
Expand Down Expand Up @@ -5144,6 +5145,130 @@ describe("Mutation.updateForm", () => {
]);
});

it("Bugifx - It should be possible to add a tranporter on a SENT BSDD when first transporter has invalid plates", async () => {
// Adding a transporter to an older SENT bsd with invalid plates used to fail

const emitter = await userWithCompanyFactory("ADMIN");
const transporter1 = await userWithCompanyFactory("MEMBER");
const transporter2 = await userWithCompanyFactory("MEMBER");

// recipient needs appropriate profiles and subprofiles
const destination = await companyFactory({
companyTypes: [CompanyType.WASTEPROCESSOR],
wasteProcessorTypes: [WasteProcessorType.DANGEROUS_WASTES_INCINERATION]
});
// Create a form that has already been signed by the first transporter
const form = await formFactory({
ownerId: emitter.user.id,
opt: {
status: Status.SENT,
emittedAt: new Date(),
takenOverAt: new Date(),
emitterCompanySiret: emitter.company.siret,
recipientCompanySiret: destination.siret,

transporters: {
create: {
transporterCompanySiret: transporter1.company.siret,
number: 1,
readyToTakeOver: true,
takenOverAt: new Date(),
transporterTransportMode: "ROAD",
transporterNumberPlate: "X"
}
}
}
});

const bsddTransporter1 = await getFirstTransporter(form);

// Transporter n°2 (not signed yet)
const bsddTransporter2 = await bsddTransporterFactory({
formId: form.id,
opts: {
transporterCompanySiret: transporter2.company.siret,
takenOverAt: null,
transporterNumberPlate: "XY-ZE-23"
}
});

const updateFormInput: UpdateFormInput = {
id: form.id,
transporters: [bsddTransporter1!.id, bsddTransporter2.id]
};
const { mutate } = makeClient(emitter.user);

const { errors } = await mutate<Pick<Mutation, "updateForm">>(UPDATE_FORM, {
variables: { updateFormInput }
});

expect(errors).toBeUndefined();
});

it("Should validate second transporter plate", async () => {
const emitter = await userWithCompanyFactory("ADMIN");
const transporter1 = await userWithCompanyFactory("MEMBER");
const transporter2 = await userWithCompanyFactory("MEMBER");

// recipient needs appropriate profiles and subprofiles
const destination = await companyFactory({
companyTypes: [CompanyType.WASTEPROCESSOR],
wasteProcessorTypes: [WasteProcessorType.DANGEROUS_WASTES_INCINERATION]
});
// Create a form that has already been signed by the first transporter
const form = await formFactory({
ownerId: emitter.user.id,
opt: {
status: Status.SENT,
emittedAt: new Date(),
takenOverAt: new Date(),
emitterCompanySiret: emitter.company.siret,
recipientCompanySiret: destination.siret,

transporters: {
create: {
transporterCompanySiret: transporter1.company.siret,
number: 1,
readyToTakeOver: true,
takenOverAt: new Date(),
transporterTransportMode: "ROAD",
transporterNumberPlate: "XY-23-AZ"
}
}
}
});

const bsddTransporter1 = await getFirstTransporter(form);

// Transporter n°2 (not signed yet)
const bsddTransporter2 = await bsddTransporterFactory({
formId: form.id,
opts: {
transporterCompanySiret: transporter2.company.siret,
takenOverAt: null,
transporterNumberPlate: "XY"
}
});

// Add second transporter
const updateFormInput: UpdateFormInput = {
id: form.id,
transporters: [bsddTransporter1!.id, bsddTransporter2.id]
};
const { mutate } = makeClient(emitter.user);

const { errors } = await mutate<Pick<Mutation, "updateForm">>(UPDATE_FORM, {
variables: { updateFormInput }
});

expect(errors).toEqual([
expect.objectContaining({
message:
"Le numéro d'immatriculation doit faire entre 4 et 12 caractères"
})
]);
});

it("should be possible to add a transporter even if BSD has intermediaries", async () => {
// Given
const emitter = await userWithCompanyFactory("ADMIN");
Expand Down
7 changes: 6 additions & 1 deletion back/src/forms/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,8 @@ export const transporterSchemaFn: FactorySchemaOf<
const {
transporterTransportMode,
transporterCompanySiret,
transporterCompanyVatNumber
transporterCompanyVatNumber,
takenOverAt
} = ctx.parent;

if (
Expand All @@ -1081,6 +1082,10 @@ export const transporterSchemaFn: FactorySchemaOf<
return true;
}

// Skip if already takenOver, useful for the multimodal because validation may be re-applied on already taken over transporters
if (takenOverAt) {
return true;
}
return validatePlates(transporterNumberPlate);
}),
transporterCompanyName: yup
Expand Down

0 comments on commit 3f3dcf0

Please sign in to comment.