-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): fix search for birth date & phone
- Loading branch information
Showing
30 changed files
with
223 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,7 +443,7 @@ | |
margin-left: 5px; | ||
" | ||
> | ||
+33 1 02 03 04 05 | ||
01 02 03 04 05 | ||
</li> | ||
</ul> | ||
<p | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,7 +443,7 @@ | |
margin-left: 5px; | ||
" | ||
> | ||
+33 1 02 03 04 05 | ||
01 02 03 04 05 | ||
</li> | ||
</ul> | ||
<p | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ export const CUSTOM_DOC_ATTESTATION_POSTALE: StructureCustomDocTags = { | |
USAGER_SURNOM: "TEST", | ||
USAGER_DATE_NAISSANCE: "02/11/1988", | ||
USAGER_LIEU_NAISSANCE: "Paris", | ||
USAGER_PHONE: "+33 6 06 06 06 06", | ||
USAGER_PHONE: "06 06 06 06 06", | ||
USAGER_EMAIL: "[email protected]", | ||
USAGER_NUMERO_DISTRIBUTION_SPECIALE: "", | ||
STATUT_DOM: "Actif", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ export const CUSTOM_DOC_COURRIER_REFUS: StructureCustomDocTags = { | |
USAGER_SURNOM: "", | ||
USAGER_DATE_NAISSANCE: "07/08/1998", | ||
USAGER_LIEU_NAISSANCE: "Bouaké, Côte d'Ivoire", | ||
USAGER_PHONE: "+33 6 06 06 06 06", | ||
USAGER_PHONE: "06 06 06 06 06", | ||
USAGER_EMAIL: "[email protected]", | ||
AYANTS_DROITS_LISTE: "Karamoko Mauricette né(e) le 20/12/1978", | ||
STATUT_DOM: "Refusé", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//@index('./*.ts', f => `export * from '${f.path}'`) | ||
export * from "./getUsagerDeadlines"; | ||
export * from "./normalize-string"; | ||
export * from "./parseBirthDate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { format, isValid, parse } from "date-fns"; | ||
|
||
export const parseBirthDate = (text: string): string | null => { | ||
const parsedDate = parse(text.trim(), "dd/MM/yyyy", new Date()); | ||
if (!isValid(parsedDate)) { | ||
return null; | ||
} | ||
const minDate = new Date(1900, 0, 1); | ||
const today = new Date(); | ||
|
||
if (parsedDate < minDate || parsedDate > today) { | ||
return null; | ||
} | ||
return format(parsedDate, "ddMMyyyy"); | ||
}; |
71 changes: 71 additions & 0 deletions
71
packages/common/src/search/functions/tests/parseBirthDate.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { parseBirthDate } from "../parseBirthDate"; | ||
|
||
describe("parseBirthDate", () => { | ||
describe("Valid Date Formats", () => { | ||
it("should parse a valid date", () => { | ||
const result = parseBirthDate("15/08/1990"); | ||
expect(result).toBe("15081990"); | ||
}); | ||
|
||
it("should handle initial zeros", () => { | ||
const result = parseBirthDate("01/02/2000"); | ||
expect(result).toBe("01022000"); | ||
}); | ||
}); | ||
|
||
describe("Date Range Validation: 1900 < date > now", () => { | ||
it("should return null for a date before 1900", () => { | ||
const result = parseBirthDate("01/01/1899"); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it("should return null for a future date", () => { | ||
const result = parseBirthDate("01/01/2045"); | ||
expect(result).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("Invalid Date Formats", () => { | ||
it("should return null for incorrect date format", () => { | ||
const result = parseBirthDate("2023-01-15"); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it("should return null for a non-existent date", () => { | ||
const result = parseBirthDate("31/02/2000"); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it("should return null for a non-numeric string", () => { | ||
const result = parseBirthDate("abc/def/ghij"); | ||
expect(result).toBeNull(); | ||
}); | ||
}); | ||
|
||
// Spaces handling tests | ||
describe("Spaces Handling", () => { | ||
it("should remove spaces before and after the date", () => { | ||
const result = parseBirthDate(" 15/08/1990 "); | ||
expect(result).toBe("15081990"); | ||
}); | ||
}); | ||
|
||
// Boundary cases tests | ||
describe("Boundary Cases", () => { | ||
it("should accept the minimum allowed date", () => { | ||
const result = parseBirthDate("01/01/1900"); | ||
expect(result).toBe("01011900"); | ||
}); | ||
|
||
it("should accept the maximum allowed date (today)", () => { | ||
const today = new Date(); | ||
const formattedToday = `${today.getDate().toString().padStart(2, "0")}/${( | ||
today.getMonth() + 1 | ||
) | ||
.toString() | ||
.padStart(2, "0")}/${today.getFullYear()}`; | ||
const result = parseBirthDate(formattedToday); | ||
expect(result).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.