Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA_15736] Permettre d'Enregistrer un VHU en brouillon lorsque le Type de conditionnement n'est pas sélectionné et afficher un message d'erreur à la publication si celui-ci est manquant #3996

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 le 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