Skip to content

Commit

Permalink
fix: dernier organisme uai en cohérence avec tous les cas sifa (+ tes…
Browse files Browse the repository at this point in the history
…ts de non-régression) (#3416)
  • Loading branch information
rap2hpoutre authored Dec 5, 2023
1 parent 0debdc9 commit fbaec68
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions server/src/common/constants/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const YEAR_RANGE_PATTERN = "^[12][0-9]{3}-[12][0-9]{3}$";
export const NIR_REGEX_PATTERN = "^[0-9]{13}$";
// Le NIR peut contenir 15 caractères (13 chiffres + 2 chiffres de contrôle)
export const NIR_LOOSE_REGEX_PATTERN = "^[0-9]{13}([0-9]{2})?$";
// Basé sur les recommandations SIFA
export const DERNIER_ORGANISME_UAI_PATTERN =
"^(0?[0-9][0-9]|0?2[AB]|0?9[012345]|97[1234678]|98[46789]|99[0135]|[0-9]{7}[a-zA-Z])$";

// Numero INE (Identifiant National Elève)
// Le numero INE composé de 11 caractères,
Expand All @@ -33,6 +36,7 @@ export const UAI_REGEX = new RegExp(UAI_REGEX_PATTERN);
export const YEAR_RANGE_REGEX = new RegExp(YEAR_RANGE_PATTERN);
export const NIR_REGEX = new RegExp(NIR_REGEX_PATTERN);
export const NIR_LOOSE_REGEX = new RegExp(NIR_LOOSE_REGEX_PATTERN);
export const DERNIER_ORGANISME_UAI_REGEX = new RegExp(DERNIER_ORGANISME_UAI_PATTERN);

export const isValidCFD = (cfd) => typeof cfd === "string" && CFD_REGEX.test(cfd);
export const isValidINE = (ine) => typeof ine === "string" && INE_REGEX.test(ine);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
NATIONALITE_APPRENANT_ENUM,
SEXE_APPRENANT_ENUM,
} from "@/common/constants/dossierApprenant";
import { CODE_POSTAL_PATTERN, INE_REGEX_PATTERN } from "@/common/constants/validations";
import { CODE_POSTAL_PATTERN, DERNIER_ORGANISME_UAI_PATTERN, INE_REGEX_PATTERN } from "@/common/constants/validations";
import { adresseSchema } from "@/common/model/json-schema/adresseSchema";
import { object, string, date, integer, boolean, arrayOf } from "@/common/model/json-schema/jsonSchemaTypes";

Expand Down Expand Up @@ -132,7 +132,7 @@ export const apprenantSchema = object(
dernier_organisme_uai: string({
description:
"Numéro UAI de l’établissement fréquenté l’année dernière (N-1), si déjà en apprentissage, mettre l’UAI du site de formation ou département",
pattern: "^([0-9][0-9]|2[AB]|9[012345]|97[1234678]|98[46789]|[0-9]{7}[a-zA-Z])$",
pattern: DERNIER_ORGANISME_UAI_PATTERN,
}),
type_cfa: string({
enum: ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"],
Expand Down
3 changes: 2 additions & 1 deletion server/src/common/validation/utils/zodPrimitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
INE_REGEX,
NIR_LOOSE_REGEX,
CODE_POSTAL_REGEX,
DERNIER_ORGANISME_UAI_REGEX,
} from "@/common/constants/validations";

import { telephoneConverter } from "./frenchTelephoneNumber";
Expand Down Expand Up @@ -460,7 +461,7 @@ export const primitivesV3 = {
}),
dernier_organisme_uai: z
.string()
.regex(/^([0-9][0-9]|2[AB]|9[012345]|97[1234678]|98[46789]|[0-9]{7}[a-zA-Z])$/, "UAI ou département")
.regex(DERNIER_ORGANISME_UAI_REGEX, "UAI ou département")
.describe(
"Numéro UAI de l’établissement fréquenté l’année dernière (N-1), si déjà en apprentissage, mettre l’UAI du site de formation ou département"
)
Expand Down
34 changes: 34 additions & 0 deletions server/tests/integration/common/constants/validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { DERNIER_ORGANISME_UAI_REGEX } from "@/common/constants/validations";

describe("Regex DERNIER_ORGANISME_UAI_REGEX", () => {
describe("Cas valides", () => {
const validValues = [
"44",
"044",
"95",
"095",
"2B",
"02B",
"972",
"986",
"990",
"991",
"993",
"995",
"0802004U",
"4422672E",
"0755805C",
];

it.each(validValues)('"%s" devrait être valide', (value) => {
expect(DERNIER_ORGANISME_UAI_REGEX.test(value)).toBeTruthy();
});
});
describe("Cas invalides", () => {
const invalidValues = ["123", "ABC", "97Z", "9865", "9900", "99123", "ABCD", "1234567890", "0X0X0X"];

it.each(invalidValues)('"%s" devrait être invalide', (value) => {
expect(DERNIER_ORGANISME_UAI_REGEX.test(value)).toBeFalsy();
});
});
});

0 comments on commit fbaec68

Please sign in to comment.