diff --git a/packages/backend/src/auth/services/structures-auth.service.ts b/packages/backend/src/auth/services/structures-auth.service.ts index c14f503289..72cbebe9e2 100644 --- a/packages/backend/src/auth/services/structures-auth.service.ts +++ b/packages/backend/src/auth/services/structures-auth.service.ts @@ -132,6 +132,7 @@ export class StructuresAuthService { "sms", "portailUsager", "acceptTerms", + "timeZone", ], }); diff --git a/packages/backend/src/usagers/services/cerfa/generateCerfaDatas.service.ts b/packages/backend/src/usagers/services/cerfa/generateCerfaDatas.service.ts index 63bf292466..c5d49b5dc9 100644 --- a/packages/backend/src/usagers/services/cerfa/generateCerfaDatas.service.ts +++ b/packages/backend/src/usagers/services/cerfa/generateCerfaDatas.service.ts @@ -19,15 +19,13 @@ export const generateCerfaDatas = ( ): UsagerCerfaFields => { const usagerRef = getUsagerRef(usager); - // Rendez-vous et entretien if (isNil(usager.rdv)) { usager.rdv = { userId: null, dateRdv: null, userName: null }; } const entretienAvec = toString(usager.rdv.userName).toUpperCase(); const dateRdv = generateDateForCerfa(usager.rdv.dateRdv, user); - // Dates de la dom - const dateDecision = generateDateForCerfa(new Date()); + const dateOfDocument = generateDateForCerfa(new Date()); const datePremiereDom = generateDateForCerfa(usager.datePremiereDom); let dateDebut = generateDateForCerfa(usager.decision.dateDebut); let dateFin = generateDateForCerfa(usager.decision.dateFin); @@ -70,9 +68,9 @@ export const generateCerfaDatas = ( adresseOrga1: adresseStructure, agrement: user.structure.agrement, anneeDebut: dateDebut.annee, - anneeDecision1A: dateDecision.annee, - anneeDecision1B: dateDecision.annee, - anneeDecision2: dateDecision.annee, + anneeDecision1A: dateOfDocument.annee, + anneeDecision1B: dateOfDocument.annee, + anneeDecision2: dateOfDocument.annee, anneeFin: dateFin.annee, anneeNaissance1: dateNaissance.annee, anneeNaissance2: dateNaissance.annee, @@ -86,9 +84,9 @@ export const generateCerfaDatas = ( entretienAvec, heureRdv: dateRdv.heure, jourDebut: dateDebut.jour, - jourDecision1A: dateDecision.jour, - jourDecision1B: dateDecision.jour, - jourDecision2: dateDecision.jour, + jourDecision1A: dateOfDocument.jour, + jourDecision1B: dateOfDocument.jour, + jourDecision2: dateOfDocument.jour, jourFin: dateFin.jour, jourNaissance1: dateNaissance.jour, jourNaissance2: dateNaissance.jour, @@ -98,9 +96,9 @@ export const generateCerfaDatas = ( lieuNaissance2: usager.villeNaissance, minutesRdv: dateRdv.minutes, moisDebut: dateDebut.mois, - moisDecision1A: dateDecision.mois, - moisDecision1B: dateDecision.mois, - moisDecision2: dateDecision.mois, + moisDecision1A: dateOfDocument.mois, + moisDecision1B: dateOfDocument.mois, + moisDecision2: dateOfDocument.mois, moisFin: dateFin.mois, moisNaissance1: dateNaissance.mois, moisNaissance2: dateNaissance.mois, diff --git a/packages/backend/src/usagers/services/cerfa/generateDateForCerfa.service.ts b/packages/backend/src/usagers/services/cerfa/generateDateForCerfa.service.ts index 6925c97f08..ff748edbf5 100644 --- a/packages/backend/src/usagers/services/cerfa/generateDateForCerfa.service.ts +++ b/packages/backend/src/usagers/services/cerfa/generateDateForCerfa.service.ts @@ -3,7 +3,7 @@ import { DateCerfa, UserStructureAuthenticated } from "../../../_common/model"; export function generateDateForCerfa( date: Date | string | null, - user?: UserStructureAuthenticated // Pour les RDV uniquement + user?: UserStructureAuthenticated ): DateCerfa { let annee = ""; let heure = ""; diff --git a/packages/backend/src/usagers/services/cerfa/tests/generateDateForCerfa.spec.ts b/packages/backend/src/usagers/services/cerfa/tests/generateDateForCerfa.spec.ts index 7546c7bc3d..d4bc0cbd7e 100644 --- a/packages/backend/src/usagers/services/cerfa/tests/generateDateForCerfa.spec.ts +++ b/packages/backend/src/usagers/services/cerfa/tests/generateDateForCerfa.spec.ts @@ -13,6 +13,7 @@ import { generateDateForCerfa } from "../generateDateForCerfa.service"; describe("generateDateForCerfa", () => { let context: AppTestContext; + let user: UserStructureAuthenticated; afterAll(async () => { jest.useRealTimers(); @@ -26,6 +27,14 @@ describe("generateDateForCerfa", () => { jest .useFakeTimers(JEST_FAKE_TIMER) .setSystemTime(new Date("2023-03-22T20:45:47.433Z")); + + user = (await userStructureRepository.findOneBy({ + id: 11, + })) as unknown as UserStructureAuthenticated; + + user.structure = await structureRepository.findOneBy({ + id: 5, + }); }); afterAll(() => { @@ -53,16 +62,17 @@ describe("generateDateForCerfa", () => { }); it("[TIMEZONE] Date au format America/Cayenne -4h (heure d'hiver)", async () => { - const user = (await userStructureRepository.findOneBy({ - id: 11, - })) as unknown as UserStructureAuthenticated; - const structure = await structureRepository.findOneBy({ - id: 5, + expect(generateDateForCerfa(new Date(), user)).toEqual({ + annee: "2023", + heure: "17", + jour: "22", + minutes: "45", + mois: "03", }); + }); - user.structure = structure; - - expect(generateDateForCerfa(new Date(), user)).toEqual({ + it("[Timezone] Date in text format for in America/Cayenne -4h format (winter time)", async () => { + expect(generateDateForCerfa("2023-03-22T20:45:47.433Z", user)).toEqual({ annee: "2023", heure: "17", jour: "22",