Skip to content

Commit

Permalink
Make vhu identificationType optional until publication
Browse files Browse the repository at this point in the history
  • Loading branch information
providenz committed Feb 25, 2025
1 parent 4b5a6fd commit 52536fc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ et le projet suit un schéma de versionning inspiré de [Calendar Versioning](ht

- Exports registres V2 : Modale d'export et petites améliorations d'UX [PR 3953](https://github.com/MTES-MCT/trackdechets/pull/3953)
- Rendre optionnel les agréments à la publication d'un VHU [PR 3953](https://github.com/MTES-MCT/trackdechets/pull/3984)
- Rendre optionnel type de conditionnement du Bsvhu en brouillon [PR 3996](https://github.com/MTES-MCT/trackdechets/pull/3996)

# [2025.02.1] 11/02/2025

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe("Mutation.Vhu.createDraft", () => {
expect(data.createDraftBsvhu.id).toBeTruthy();
});

it("should fail when packaging is UNITE and identificationType is null", async () => {
it("should succeed when packaging is UNITE and identificationType is null", async () => {
const { user, company } = await userWithCompanyFactory("MEMBER");
const destinationCompany = await companyFactory({
companyTypes: ["WASTE_VEHICLES"],
Expand Down Expand Up @@ -392,7 +392,7 @@ describe("Mutation.Vhu.createDraft", () => {
}
};
const { mutate } = makeClient(user);
const { errors } = await mutate<Pick<Mutation, "createDraftBsvhu">>(
const { data, errors } = await mutate<Pick<Mutation, "createDraftBsvhu">>(
CREATE_VHU_FORM,
{
variables: {
Expand All @@ -401,15 +401,8 @@ describe("Mutation.Vhu.createDraft", () => {
}
);

expect(errors).toEqual([
expect.objectContaining({
message:
"identificationType : Le type d'identification est obligatoire quand le conditionnement est en unité",
extensions: expect.objectContaining({
code: ErrorCode.BAD_USER_INPUT
})
})
]);
expect(errors).toBeUndefined();
expect(data.createDraftBsvhu.id).toBeTruthy();
});

it.each([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,36 @@ describe("Mutation.Vhu.publish", () => {
})
]);
});

it("should fail when packaging is UNITE and identificationType is nullshould pass the form as non draft", async () => {
const { user, company } = await userWithCompanyFactory("MEMBER");
const form = await bsvhuFactory({
userId: user.id,
opt: {
emitterCompanySiret: company.siret,
isDraft: true,
packaging: "UNITE",
identificationType: null
}
});

const { mutate } = makeClient(user);
const { errors } = await mutate<Pick<Mutation, "publishBsvhu">>(
PUBLISH_VHU_FORM,
{
variables: { id: form.id }
}
);

expect(errors).toEqual([
expect.objectContaining({
message:
"identificationType : Le type d'identification est obligatoire quand le conditionnement est en unité\n" +
"Le type de numéro d'identification est un champ requis.",
extensions: expect.objectContaining({
code: ErrorCode.BAD_USER_INPUT
})
})
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,12 @@ describe("Mutation.Vhu.update", () => {
expect(data.updateBsvhu.identification?.type).toEqual(null);
});

it("should fail when packaging is UNITE and identificationType is null", async () => {
it("should fail when packaging is UNITE and identificationType is null on a published bsvhu", async () => {
const { company, user } = await userWithCompanyFactory(UserRole.ADMIN);
const bsvhu = await bsvhuFactory({
userId: user.id,
opt: {
isDraft: true,
isDraft: false,
status: "INITIAL",
emitterCompanySiret: company.siret
}
Expand Down Expand Up @@ -786,6 +786,34 @@ describe("Mutation.Vhu.update", () => {
]);
});

it("should succeed when packaging is UNITE and identificationType is null on a draft bsvhu", async () => {
const { company, user } = await userWithCompanyFactory(UserRole.ADMIN);
const bsvhu = await bsvhuFactory({
userId: user.id,
opt: {
isDraft: true,
status: "INITIAL",
emitterCompanySiret: company.siret
}
});
const { mutate } = makeClient(user);
const input = {
packaging: "UNITE",
identification: {
numbers: ["123", "456"],
type: null
}
};
const { errors } = await mutate<Pick<Mutation, "updateBsvhu">>(
UPDATE_VHU_FORM,
{
variables: { id: bsvhu.id, input }
}
);

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

it("should succeed when packaging is UNITE and identificationType is null on a bsvhu created before release date", async () => {
const { company, user } = await userWithCompanyFactory(UserRole.ADMIN);
const bsvhu = await bsvhuFactory({
Expand Down
8 changes: 6 additions & 2 deletions back/src/bsvhu/validation/refinements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ export const checkPackagingAndIdentificationType: Refinement<ParsedZodBsvhu> = (
"identificationType : Le type d'identification doit être null quand le conditionnement est en lot"
});
}

if (bsvhu.packaging === "UNITE" && !bsvhu.identificationType) {
// Must not apply on draft bsvhus
if (
!bsvhu.isDraft &&
bsvhu.packaging === "UNITE" &&
!bsvhu.identificationType
) {
addIssue({
code: z.ZodIssueCode.custom,
path: ["identification", "type"],
Expand Down

0 comments on commit 52536fc

Please sign in to comment.