Skip to content

Commit

Permalink
fix(cerfa): correction d'un bug sur les dates
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Sep 5, 2023
1 parent e28b143 commit 3bd0a11
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class StructuresAuthService {
"sms",
"portailUsager",
"acceptTerms",
"timeZone",
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { generateDateForCerfa } from "../generateDateForCerfa.service";

describe("generateDateForCerfa", () => {
let context: AppTestContext;
let user: UserStructureAuthenticated;

afterAll(async () => {
jest.useRealTimers();
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3bd0a11

Please sign in to comment.