Skip to content

Commit 898f7d3

Browse files
committed
fix(backend): fix cerfa type
1 parent 3649d0f commit 898f7d3

File tree

5 files changed

+172
-10
lines changed

5 files changed

+172
-10
lines changed

packages/backend/src/_migrations/1748870856744-manual-migration.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ export class ManualMigration1748870856744 implements MigrationInterface {
99
domifaConfig().envId === "preprod" ||
1010
domifaConfig().envId === "local"
1111
) {
12-
await queryRunner.query(
13-
`ALTER TABLE "open_data_cities" ADD "populationSegment" text`
14-
);
15-
await queryRunner.query(
16-
`ALTER TABLE "open_data_places" ADD "domicilieSegment" text`
17-
);
12+
try {
13+
await queryRunner.query(
14+
`ALTER TABLE "open_data_cities" ADD "populationSegment" text`
15+
);
16+
await queryRunner.query(
17+
`ALTER TABLE "open_data_places" ADD "domicilieSegment" text`
18+
);
19+
} catch (e) {
20+
console.log(e);
21+
}
1822
}
1923
}
2024

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { getNextClosestDay } from "./generateScheduleSendDate";
2+
3+
describe("getNextClosestDay", () => {
4+
describe("Input validation", () => {
5+
it("should throw error when no working days are provided", () => {
6+
const date = new Date("2024-03-15T10:00:00"); // Friday
7+
expect(() => getNextClosestDay([], date)).toThrow(
8+
"No working days enabled in schedule"
9+
);
10+
});
11+
12+
it("should throw error when only weekend days are provided", () => {
13+
const date = new Date("2024-03-15T10:00:00"); // Friday
14+
expect(() => getNextClosestDay(["saturday", "sunday"], date)).toThrow(
15+
"No working days enabled in schedule"
16+
);
17+
});
18+
19+
it("should handle case insensitive day names", () => {
20+
const date = new Date("2024-03-15T10:00:00"); // Friday
21+
const result = getNextClosestDay(
22+
["MONDAY", "Tuesday", "wEdNeSdAy"],
23+
date
24+
);
25+
expect(result).toBe(1); // Monday
26+
});
27+
});
28+
29+
describe("Weekend cases", () => {
30+
it("should return first available day when current day is Saturday", () => {
31+
const date = new Date("2024-03-16T10:00:00"); // Saturday
32+
const result = getNextClosestDay(["monday", "wednesday", "friday"], date);
33+
expect(result).toBe(1); // Monday
34+
});
35+
36+
it("should return first available day when current day is Sunday", () => {
37+
const date = new Date("2024-03-17T10:00:00"); // Sunday
38+
const result = getNextClosestDay(["tuesday", "thursday"], date);
39+
expect(result).toBe(2); // Tuesday
40+
});
41+
});
42+
43+
describe("Friday after hours cases", () => {
44+
it("should return first available day when Friday at exactly 19h", () => {
45+
const date = new Date("2024-03-15T19:00:00"); // Friday 19h
46+
const result = getNextClosestDay(["monday", "wednesday"], date);
47+
expect(result).toBe(1); // Monday
48+
});
49+
50+
it("should return first available day when Friday after 19h", () => {
51+
const date = new Date("2024-03-15T20:30:00"); // Friday 20h30
52+
const result = getNextClosestDay(["tuesday", "thursday"], date);
53+
expect(result).toBe(2); // Tuesday
54+
});
55+
56+
it("should not trigger after hours logic when Friday before 19h", () => {
57+
const date = new Date("2024-03-15T18:59:00"); // Friday 18h59
58+
const result = getNextClosestDay(["friday", "monday"], date);
59+
expect(result).toBe(5); // Friday (same day)
60+
});
61+
});
62+
63+
describe("Weekday before 19h cases", () => {
64+
it("should return same day if available and before 19h on Monday", () => {
65+
const date = new Date("2024-03-11T10:00:00"); // Monday 10h
66+
const result = getNextClosestDay(["monday", "wednesday"], date);
67+
expect(result).toBe(1); // Monday
68+
});
69+
70+
it("should return same day if available and before 19h on Tuesday", () => {
71+
const date = new Date("2024-03-12T15:00:00"); // Tuesday 15h
72+
const result = getNextClosestDay(["tuesday", "friday"], date);
73+
expect(result).toBe(2); // Tuesday
74+
});
75+
76+
it("should return next available day if current day not in schedule", () => {
77+
const date = new Date("2024-03-12T10:00:00"); // Tuesday 10h
78+
const result = getNextClosestDay(["wednesday", "friday"], date);
79+
expect(result).toBe(3); // Wednesday
80+
});
81+
82+
it("should wrap to first day of next week if no more days this week", () => {
83+
const date = new Date("2024-03-14T10:00:00"); // Thursday 10h
84+
const result = getNextClosestDay(["monday", "tuesday"], date);
85+
expect(result).toBe(1); // Monday (next week)
86+
});
87+
});
88+
89+
describe("Weekday after 19h cases", () => {
90+
it("should return next day when Monday after 19h", () => {
91+
const date = new Date("2024-03-11T19:30:00"); // Monday 19h30
92+
const result = getNextClosestDay(
93+
["monday", "tuesday", "wednesday"],
94+
date
95+
);
96+
expect(result).toBe(2); // Tuesday
97+
});
98+
99+
it("should return next day when Tuesday after 19h", () => {
100+
const date = new Date("2024-03-12T20:00:00"); // Tuesday 20h
101+
const result = getNextClosestDay(["tuesday", "thursday"], date);
102+
expect(result).toBe(4); // Thursday
103+
});
104+
105+
it("should wrap to next week when Thursday after 19h and Friday not available", () => {
106+
const date = new Date("2024-03-14T19:30:00"); // Thursday 19h30
107+
const result = getNextClosestDay(["monday", "tuesday", "thursday"], date);
108+
expect(result).toBe(1); // Monday (next week)
109+
});
110+
});
111+
112+
describe("Complex scheduling scenarios", () => {
113+
it("should handle case: Thursday enabled, current day is Friday - should return Thursday next week", () => {
114+
const date = new Date("2024-03-15T10:00:00"); // Friday 10h
115+
const result = getNextClosestDay(["thursday"], date);
116+
expect(result).toBe(4); // Thursday (next week)
117+
});
118+
119+
it("should handle multiple non-consecutive days", () => {
120+
const date = new Date("2024-03-12T20:00:00"); // Tuesday after 19h
121+
const result = getNextClosestDay(["monday", "thursday", "friday"], date);
122+
expect(result).toBe(4); // Thursday
123+
});
124+
125+
it("should handle single day scheduling", () => {
126+
const date = new Date("2024-03-13T10:00:00"); // Wednesday 10h
127+
const result = getNextClosestDay(["friday"], date);
128+
expect(result).toBe(5); // Friday
129+
});
130+
131+
it("should handle all working days enabled", () => {
132+
const date = new Date("2024-03-13T20:00:00"); // Wednesday after 19h
133+
const result = getNextClosestDay(
134+
["monday", "tuesday", "wednesday", "thursday", "friday"],
135+
date
136+
);
137+
expect(result).toBe(4); // Thursday
138+
});
139+
});
140+
141+
describe("Edge cases with hour boundaries", () => {
142+
it("should handle exactly 18h59 (before cutoff)", () => {
143+
const date = new Date("2024-03-13T18:59:59"); // Wednesday 18h59m59s
144+
const result = getNextClosestDay(["wednesday", "friday"], date);
145+
expect(result).toBe(3); // Wednesday (same day)
146+
});
147+
148+
it("should handle exactly 19h00 (at cutoff)", () => {
149+
const date = new Date("2024-03-13T19:00:00"); // Wednesday 19h00
150+
const result = getNextClosestDay(["wednesday", "friday"], date);
151+
expect(result).toBe(5); // Friday (next day)
152+
});
153+
154+
it("should handle midnight (0h00)", () => {
155+
const date = new Date("2024-03-13T00:00:00"); // Wednesday 0h00
156+
const result = getNextClosestDay(["wednesday", "friday"], date);
157+
expect(result).toBe(3); // Wednesday (same day)
158+
});
159+
});
160+
});

packages/common/src/structure-doc/constants/STRUCTURE_CUSTOM_DOCS_AVAILABLE.const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { StructureCustomDocType } from "../types";
44
export const DEFAULT_STRUCTURE_CUSTOM_DOC_AVAILABLE: StructureCustomDocType[] =
55
[
66
StructureDocTypesAvailable.attestation_postale,
7-
// StructureDocTypesAvailable.cerfa_attestation,
7+
StructureDocTypesAvailable.cerfa_attestation,
88
StructureDocTypesAvailable.courrier_radiation,
99
];
1010

packages/common/src/structure-doc/enums/StructureDocTypesAvailable.enum.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ export enum StructureDocTypesAvailable {
22
attestation_postale = "attestation_postale",
33
cerfa_attestation = "cerfa_attestation",
44
courrier_radiation = "courrier_radiation",
5-
// cerfa_demande = "cerfa_demande",
6-
// carte_domicilie = "carte_domicilie",
75
acces_espace_domicilie = "acces_espace_domicilie",
86
}

packages/frontend/src/app/modules/manage-usagers/components/manage-download-docs/manage-download-docs.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"
7878
>
7979
<fa-icon aria-hidden="true" [icon]="faFileWord"></fa-icon>
80-
Télécharger le Cerfa d'attestation de domicile (.docx)
80+
Télécharger le Cerfa d'élection de domicile (.docx)
8181
</button>
8282
</div>
8383
</div>

0 commit comments

Comments
 (0)