Skip to content

Commit 63b3a0d

Browse files
fix(BSDD): TRA-14096: fixer les tests d integrations
1 parent 21dcf21 commit 63b3a0d

File tree

3 files changed

+80
-80
lines changed

3 files changed

+80
-80
lines changed

back/src/forms/__tests__/edition.integration.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -522,29 +522,28 @@ describe("checkEditionRules", () => {
522522
expect(checked).toEqual(true);
523523
});
524524

525-
it("should not be possible to change intermediaries when the form is signed by emitter", async () => {
526-
const destination = await userWithCompanyFactory("MEMBER");
527-
const intermediary1 = await userWithCompanyFactory("MEMBER");
528-
const intermediary2 = await userWithCompanyFactory("MEMBER");
529-
530-
const form = await formFactory({
531-
ownerId: destination.user.id,
532-
opt: {
533-
status: Status.SIGNED_BY_PRODUCER,
534-
emittedAt: new Date(),
535-
intermediaries: { create: toIntermediaryCompany(intermediary1.company) }
536-
}
537-
});
538-
const fullForm = await getFullForm(form);
539-
const input: UpdateFormInput = {
540-
id: form.id,
541-
intermediaries: [toIntermediaryCompany(intermediary2.company)] // try changing the intermediary
542-
};
543-
const checkFn = () => checkEditionRules(fullForm, input, destination.user);
544-
await expect(checkFn).rejects.toThrow(
545-
"Des champs ont été verrouillés via signature et ne peuvent plus être modifiés : intermediaries"
546-
);
525+
it("should be possible to change intermediaries when the form is signed by emitter (before RECEIVED)", async () => {
526+
const destination = await userWithCompanyFactory("MEMBER");
527+
const intermediary1 = await userWithCompanyFactory("MEMBER");
528+
const intermediary2 = await userWithCompanyFactory("MEMBER");
529+
530+
const form = await formFactory({
531+
ownerId: destination.user.id,
532+
opt: {
533+
status: Status.SIGNED_BY_PRODUCER,
534+
emittedAt: new Date(),
535+
intermediaries: { create: toIntermediaryCompany(intermediary1.company) }
536+
}
547537
});
538+
const fullForm = await getFullForm(form);
539+
const input: UpdateFormInput = {
540+
id: form.id,
541+
intermediaries: [toIntermediaryCompany(intermediary2.company)]
542+
};
543+
const checkFn = () => checkEditionRules(fullForm, input, destination.user);
544+
545+
await expect(checkFn()).resolves.toBe(true);
546+
});
548547

549548
it("should be possible to resend same intermediaries info when the form is is signed by emitter", async () => {
550549
const destination = await userWithCompanyFactory("MEMBER");

back/src/forms/resolvers/mutations/__tests__/markAsAccepted.integration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,14 @@ describe("Test Form reception", () => {
479479
expect.objectContaining({
480480
subject:
481481
"Le déchet de l’entreprise company_1 a été partiellement refusé à réception",
482-
to: [
482+
to: expect.arrayContaining([
483483
{ email: emitter.email, name: emitter.name },
484484
{ email: emitter2.email, name: emitter2.name }
485-
],
486-
cc: [
485+
]),
486+
cc: expect.arrayContaining([
487487
{ email: recipient.email, name: recipient.name },
488488
{ email: recipient2.email, name: recipient2.name }
489-
]
489+
])
490490
})
491491
);
492492
});

back/src/forms/resolvers/mutations/__tests__/updateForm.integration.ts

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -293,69 +293,70 @@ describe("Mutation.updateForm", () => {
293293
expect(errors).toBeUndefined();
294294
});
295295

296-
it("should not be possible to update intermediaries when emitter has signed", async () => {
297-
const emitter = await userWithCompanyFactory("ADMIN");
298-
const destination = await userWithCompanyFactory("ADMIN", {
299-
companyTypes: [CompanyType.WASTEPROCESSOR],
300-
wasteProcessorTypes: [WasteProcessorType.DANGEROUS_WASTES_INCINERATION]
301-
});
302-
const intermediary1 = await companyFactory();
303-
const intermediary2 = await companyFactory();
304-
const form = await formFactory({
305-
ownerId: emitter.user.id,
306-
opt: {
307-
status: "SIGNED_BY_PRODUCER",
308-
emitterCompanySiret: emitter.company.siret,
309-
recipientCompanySiret: destination.company.siret,
310-
emittedAt: new Date(),
311-
intermediaries: { create: toIntermediaryCompany(intermediary1) }
312-
}
313-
});
314-
const { mutate } = makeClient(destination.user);
296+
it("should not be possible to update intermediaries when form is RECEIVED", async () => {
297+
const emitter = await userWithCompanyFactory("ADMIN");
298+
const destination = await userWithCompanyFactory("ADMIN", {
299+
companyTypes: [CompanyType.WASTEPROCESSOR],
300+
wasteProcessorTypes: [WasteProcessorType.DANGEROUS_WASTES_INCINERATION]
301+
});
302+
const intermediary1 = await companyFactory();
303+
const intermediary2 = await companyFactory();
304+
const form = await formFactory({
305+
ownerId: emitter.user.id,
306+
opt: {
307+
status: "RECEIVED",
308+
emitterCompanySiret: emitter.company.siret,
309+
recipientCompanySiret: destination.company.siret,
310+
emittedAt: new Date(),
311+
receivedAt: new Date(),
312+
intermediaries: { create: toIntermediaryCompany(intermediary1) }
313+
}
314+
});
315+
const { mutate } = makeClient(destination.user);
315316

316317
// Try changing the list of intermediaries
317-
const { errors: errors1 } = await mutate<
318-
Pick<Mutation, "updateForm">,
319-
MutationUpdateFormArgs
320-
>(UPDATE_FORM, {
321-
variables: {
322-
updateFormInput: {
323-
id: form.id,
324-
intermediaries: [toIntermediaryCompany(intermediary2)]
325-
}
318+
const { errors: errors1 } = await mutate<
319+
Pick<Mutation, "updateForm">,
320+
MutationUpdateFormArgs
321+
>(UPDATE_FORM, {
322+
variables: {
323+
updateFormInput: {
324+
id: form.id,
325+
intermediaries: [toIntermediaryCompany(intermediary2)]
326326
}
327-
});
327+
}
328+
});
328329

329-
expect(errors1).toEqual([
330-
expect.objectContaining({
331-
message:
332-
"Des champs ont été verrouillés via signature et ne peuvent plus être modifiés : intermediaries"
333-
})
334-
]);
330+
expect(errors1).toEqual([
331+
expect.objectContaining({
332+
message:
333+
"Des champs ont été verrouillés via signature et ne peuvent plus être modifiés : intermediaries"
334+
})
335+
]);
335336

336337
// Try changing one field on the same intermediary
337-
const { errors: errors2 } = await mutate<
338-
Pick<Mutation, "updateForm">,
339-
MutationUpdateFormArgs
340-
>(UPDATE_FORM, {
341-
variables: {
342-
updateFormInput: {
343-
id: form.id,
344-
intermediaries: [
345-
{ ...toIntermediaryCompany(intermediary2), name: "new name" }
346-
]
347-
}
338+
const { errors: errors2 } = await mutate<
339+
Pick<Mutation, "updateForm">,
340+
MutationUpdateFormArgs
341+
>(UPDATE_FORM, {
342+
variables: {
343+
updateFormInput: {
344+
id: form.id,
345+
intermediaries: [
346+
{ ...toIntermediaryCompany(intermediary2), name: "new name" }
347+
]
348348
}
349-
});
350-
351-
expect(errors2).toEqual([
352-
expect.objectContaining({
353-
message:
354-
"Des champs ont été verrouillés via signature et ne peuvent plus être modifiés : intermediaries"
355-
})
356-
]);
349+
}
357350
});
358351

352+
expect(errors2).toEqual([
353+
expect.objectContaining({
354+
message:
355+
"Des champs ont été verrouillés via signature et ne peuvent plus être modifiés : intermediaries"
356+
})
357+
]);
358+
});
359+
359360
it("should be possible to resend same intermediaries data when emitter has signed", async () => {
360361
const emitter = await userWithCompanyFactory("ADMIN");
361362
const destination = await userWithCompanyFactory("ADMIN", {

0 commit comments

Comments
 (0)