Skip to content

Commit

Permalink
Fix vhu identification number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
providenz committed Jan 7, 2025
1 parent 8ecc230 commit fecae38
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ et le projet suit un schéma de versionning inspiré de [Calendar Versioning](ht

- Supprimer l'annexe 2 d'un BSDD de regroupement lorsque celle-ci a bien été retirée [PR 3874](https://github.com/MTES-MCT/trackdechets/pull/3874).
- Au chargement des quantités du tableau des Annexes 2, bien récupérer la quantité acceptée par l'installation de destination finale et non par l'entreposage provisoire (si BSDD-suite à regrouper) à la modification [PR 3875](https://github.com/MTES-MCT/trackdechets/pull/3875)
- Les numéros d'identification du bsvhus ne devraient pas être obligatoires pour les vhus créés avant l'ajout de la règle [PR 3877](https://github.com/MTES-MCT/trackdechets/pull/3877)

#### :boom: Breaking changes

Expand Down
46 changes: 46 additions & 0 deletions back/src/bsvhu/validation/__tests__/validation.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ describe("BSVHU validation", () => {
expect(parsed).toBeDefined();
});

test("when identification numbers are not provided on a bsvhu created before v20241001", async () => {
const data: ZodBsvhu = {
...bsvhu,
createdAt: new Date("2024-10-21T00:00:00.000"), // before v20241001

identificationNumbers: [],

transporterTransportMode: "ROAD",

transporterTransportPlates: ["XY-23-TR"]
};

const parsed = await parseBsvhuAsync(data, {
...context,
currentSignatureType: "TRANSPORT"
});

expect(parsed).toBeDefined();
});

test.each([
TransportMode.RAIL,
TransportMode.AIR,
Expand Down Expand Up @@ -887,6 +907,32 @@ describe("BSVHU validation", () => {
}
);

test("when identification numbers are not provided on a bsvhu created after v20241001", async () => {
const data: ZodBsvhu = {
...bsvhu,

identificationNumbers: [],

transporterTransportMode: "ROAD",

transporterTransportPlates: ["XY-23-TR"]
};

expect.assertions(1);

try {
await parseBsvhuAsync(data, {
...context,
currentSignatureType: "TRANSPORT"
});
} catch (err) {
expect((err as ZodError).issues).toEqual([
expect.objectContaining({
message: "Les numéros d'identification est un champ requis."
})
]);
}
});
describe("Emitter transports own waste", () => {
it("allowed if exemption", async () => {
const data: ZodBsvhu = {
Expand Down
2 changes: 2 additions & 0 deletions back/src/bsvhu/validation/refinements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export const checkEmitterSituation: Refinement<ParsedZodBsvhu> = (
});
}
};
// Date de la MAJ 2024.10.1 qui rend obligatoire la complétion des numéros d'identification
export const v20241001 = new Date("2024-10-23T00:00:00.000");

// Date de la MAJ 2024.12.1 qui modifie les règles de validation de BsvhuInput.packaging et identification.type
export const v20241201 = new Date(
Expand Down
13 changes: 10 additions & 3 deletions back/src/bsvhu/validation/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { capitalize } from "../../common/strings";
import { SealedFieldError } from "../../common/errors";
import { Leaves } from "../../types";
import { v20250101 } from "./refinements";
import { v20250101, v20241001 } from "./refinements";

// Liste des champs éditables sur l'objet Bsvhu
export type BsvhuEditableFields = Required<
Expand Down Expand Up @@ -386,8 +386,15 @@ export const bsvhuEditionRules: BsvhuEditionRules = {
path: ["packaging"]
},
identificationNumbers: {
sealed: { from: sealedFromEmissionExceptForEmitter },
required: { from: "EMISSION" },
sealed: {
from: sealedFromEmissionExceptForEmitter
},
required: {
from: "EMISSION",
when: bsvhu => {
return (bsvhu.createdAt || new Date()).getTime() >= v20241001.getTime();
}
},
readableFieldName: "Les numéros d'identification",
path: ["identification", "numbers"]
},
Expand Down

0 comments on commit fecae38

Please sign in to comment.