diff --git a/modele/data_client.ts b/modele/data_client.ts index 496f4cf3cb29a203c51c007bfd95ec59d308b0d4..19a5215f7688bec3a27d95e6ae1ec7198c0d6015 100644 --- a/modele/data_client.ts +++ b/modele/data_client.ts @@ -27,6 +27,10 @@ class Client { return this._id_cli; } set id_cli(value: string) { + const idNumber = Number(value); + if (!Number.isInteger(idNumber) || idNumber <= 0) { + throw new Error("id_cli doit être un entier supérieur à 0"); + } this._id_cli = value; } @@ -34,6 +38,9 @@ class Client { return this._civ_cli; } set civ_cli(value: string) { + if (value !== "M." && value !== "Mme") { + throw new Error('civ_cli doit être "M." ou "Mme"'); + } this._civ_cli = value; } @@ -41,6 +48,9 @@ class Client { return this._nom_cli; } set nom_cli(value: string) { + if (value.length < 2 || !/^[a-zA-Z]+$/.test(value)) { + throw new Error("nom_cli doit avoir au moins 2 caractères alphabétiques"); + } this._nom_cli = value; } @@ -48,6 +58,9 @@ class Client { return this._prenom_cli; } set prenom_cli(value: string) { + if (value.length < 2 || !/^[a-zA-Z]+$/.test(value)) { + throw new Error("prenom_cli doit avoir au moins 2 caractères alphabétiques"); + } this._prenom_cli = value; } @@ -62,6 +75,9 @@ class Client { return this._mel_cli; } set mel_cli(value: string) { + if (!value.includes("@")) { + throw new Error("mel_cli doit contenir au moins un '@'"); + } this._mel_cli = value; } @@ -69,6 +85,9 @@ class Client { return this._adr_cli; } set adr_cli(value: string) { + if (value.length < 15) { + throw new Error("adr_cli doit avoir au moins 15 caractères"); + } this._adr_cli = value; } @@ -83,6 +102,9 @@ class Client { return this._commune_cli; } set commune_cli(value: string) { + if (value.length < 2) { + throw new Error("commune_cli doit avoir au moins 2 caractères"); + } this._commune_cli = value; } @@ -90,7 +112,12 @@ class Client { return this._tauxmax_remise_cli; } set tauxmax_remise_cli(value: string) { + const taux = Number(value); + if (isNaN(taux) || taux < 0 || taux > 100) { + throw new Error("tauxmax_remise_cli doit être un nombre entre 0 et 100"); + } this._tauxmax_remise_cli = value; } } + export { Client } \ No newline at end of file diff --git a/modele/data_facture.ts b/modele/data_facture.ts index c98cc0d1f6ade80800af559beda0f494de91b1ff..765e96f241153e3c6b7ac835c9243d6de0b45906 100644 --- a/modele/data_facture.ts +++ b/modele/data_facture.ts @@ -1,4 +1,4 @@ -class Facture { +class Facture { private _num_fact: string; private _date_fact: string; private _comment_fact: string; @@ -6,7 +6,7 @@ class Facture { private _id_cli: string; private _id_forfait: string; - constructor(num_fact = "", date_fact = "", comment_fact = "", taux_remise_fact = "", id_cli = "", id_forfait= "") { + constructor(num_fact = "", date_fact = "", comment_fact = "", taux_remise_fact = "", id_cli = "", id_forfait = "") { this._num_fact = num_fact; this._date_fact = date_fact; this._comment_fact = comment_fact; @@ -19,6 +19,10 @@ class Facture { return this._num_fact; } set num_fact(value: string) { + const num = Number(value); + if (!Number.isInteger(num) || num <= 0) { + throw new Error("num_fact doit être un entier supérieur à 0"); + } this._num_fact = value; } @@ -26,6 +30,9 @@ class Facture { return this._date_fact; } set date_fact(value: string) { + if (isNaN(Date.parse(value))) { + throw new Error("date_fact doit être une date valide"); + } this._date_fact = value; } @@ -40,6 +47,10 @@ class Facture { return this._taux_remise_fact; } set taux_remise_fact(value: string) { + const taux = Number(value); + if (isNaN(taux) || taux < 0 || taux > 100) { + throw new Error("taux_remise_fact doit être un nombre entre 0 et 100"); + } this._taux_remise_fact = value; } @@ -47,6 +58,10 @@ class Facture { return this._id_cli; } set id_cli(value: string) { + const idNumber = Number(value); + if (!Number.isInteger(idNumber) || idNumber <= 0) { + throw new Error("id_cli doit être un entier supérieur à 0"); + } this._id_cli = value; } @@ -57,4 +72,5 @@ class Facture { this._id_forfait = value; } } -export { Facture }; \ No newline at end of file + +export { Facture } diff --git a/modele/data_forfait.ts b/modele/data_forfait.ts index 862965b8b638043078cf5c67f9151e8647e2ed7b..b588b166b5cb12a685e543651f076bcdc8b95ca6 100644 --- a/modele/data_forfait.ts +++ b/modele/data_forfait.ts @@ -13,6 +13,9 @@ class Forfait_livraison { return this._lib_forfait; } set lib_forfait(value: string) { + if (value.length < 5) { + throw new Error("lib_forfait doit avoir au moins 5 caractères"); + } this._lib_forfait = value; } @@ -20,6 +23,9 @@ class Forfait_livraison { return this._id_forfait; } set id_forfait(value: string) { + if (value.length < 3 || value.length > 6) { + throw new Error("id_forfait doit être une chaîne entre 3 et 6 caractères"); + } this._id_forfait = value; } @@ -27,7 +33,12 @@ class Forfait_livraison { return this._mt_forfait; } set mt_forfait(value: string) { + const montant = Number(value); + if (isNaN(montant) || montant <= 0) { + throw new Error("mt_forfait doit être un réel supérieur à 0"); + } this._mt_forfait = value; } } + export { Forfait_livraison } \ No newline at end of file diff --git a/modele/data_ligne.ts b/modele/data_ligne.ts index 96fd8a6105730d1cbb4e1e0fef638b65fcc48ef8..7e9a96063b63cc5401b22219c2decf6c16e06467 100644 --- a/modele/data_ligne.ts +++ b/modele/data_ligne.ts @@ -27,6 +27,10 @@ class Ligne { return this._qte_prod; } set qte_prod(value: string) { + const quantite = Number(value); + if (!Number.isInteger(quantite) || quantite <= 0) { + throw new Error("qte_prod doit être un entier supérieur à 0"); + } this._qte_prod = value; } } diff --git a/modele/data_produit.ts b/modele/data_produit.ts index 33d07e3b7e9b91310a318a260cd86f0a9348ef6b..f86f1b76cbc149affdc210a101ffe56953398ae4 100644 --- a/modele/data_produit.ts +++ b/modele/data_produit.ts @@ -19,6 +19,9 @@ class Produit { return this._code_prod; } set code_prod(value: string) { + if (value.length < 3 || value.length > 8) { + throw new Error("code_prod doit être une chaîne de 3 à 8 caractères"); + } this._code_prod = value; } @@ -26,6 +29,9 @@ class Produit { return this._lib_prod; } set lib_prod(value: string) { + if (value.length < 4) { + throw new Error("lib_prod doit avoir au moins 4 caractères"); + } this._lib_prod = value; } @@ -33,6 +39,9 @@ class Produit { return this._type; } set type(value: string) { + if (value !== "plate" && value !== "pétillante") { + throw new Error('type doit être "plate" ou "pétillante"'); + } this._type = value; } @@ -40,6 +49,9 @@ class Produit { return this._origine; } set origine(value: string) { + if (value.length < 3) { + throw new Error("origine doit avoir au moins 3 caractères"); + } this._origine = value; } @@ -47,6 +59,10 @@ class Produit { return this._conditionnement; } set conditionnement(value: string) { + const cond = Number(value); + if (!Number.isInteger(cond) || cond < 25 || cond > 200) { + throw new Error("conditionnement doit être un entier entre 25 et 200"); + } this._conditionnement = value; } @@ -54,7 +70,12 @@ class Produit { return this._tarif_ht; } set tarif_ht(value: string) { + const tarif = Number(value); + if (isNaN(tarif) || tarif <= 0) { + throw new Error("tarif_ht doit être un réel supérieur à 0"); + } this._tarif_ht = value; } } + export { Produit } diff --git a/modele/test_data.test.ts b/modele/test_data.test.ts index 9359c2a50109d90eb23de55271ae5066d7ead4f2..6654636d1b82cfc3c4658f04a219b2e4fb56b132 100644 --- a/modele/test_data.test.ts +++ b/modele/test_data.test.ts @@ -21,6 +21,140 @@ Deno.test("Client initialisation compléte correcte", () => { assertEquals(client.tauxmax_remise_cli, "10"); }); +// Tests des setters avec valeurs incorrectes + +Deno.test("Set id_cli négatif", () => { + const a = new Client(); + assertThrows(() => a.id_cli = "-1", Error); +}); + +Deno.test("Set id_cli zéro", () => { + const a = new Client(); + assertThrows(() => a.id_cli = "0", Error); +}); + +Deno.test("Set id_cli non entier", () => { + const a = new Client(); + assertThrows(() => a.id_cli = "abc", Error); +}); + +Deno.test("Set civ_cli invalide", () => { + const a = new Client(); + assertThrows(() => a.civ_cli = "Dr", Error); +}); + +Deno.test("Set nom_cli trop court", () => { + const a = new Client(); + assertThrows(() => a.nom_cli = "P", Error); +}); + +Deno.test("Set nom_cli avec non alphabetique", () => { + const a = new Client(); + assertThrows(() => a.nom_cli = "P1", Error); +}); + +Deno.test("Set prenom_cli trop court", () => { + const a = new Client(); + assertThrows(() => a.prenom_cli = "H", Error); +}); + +Deno.test("Set prenom_cli avec non alphabetique", () => { + const a = new Client(); + assertThrows(() => a.prenom_cli = "H1", Error); +}); + +Deno.test("Set mel_cli sans '@'", () => { + const a = new Client(); + assertThrows(() => a.mel_cli = "huguesporchet.com", Error); +}); + +Deno.test("Set adr_cli trop court", () => { + const a = new Client(); + assertThrows(() => a.adr_cli = "4 place", Error); +}); + +Deno.test("Set commune_cli trop court", () => { + const a = new Client(); + assertThrows(() => a.commune_cli = "M", Error); +}); + +Deno.test("Set tauxmax_remise_cli négatif", () => { + const a = new Client(); + assertThrows(() => a.tauxmax_remise_cli = "-1", Error); +}); + +Deno.test("Set tauxmax_remise_cli supérieur à 100", () => { + const a = new Client(); + assertThrows(() => a.tauxmax_remise_cli = "101", Error); +}); + +Deno.test("Set tauxmax_remise_cli non numérique", () => { + const a = new Client(); + assertThrows(() => a.tauxmax_remise_cli = "abc", Error); +}); + +// Tests pour les setters de Client + +Deno.test("Set id_cli correctement", () => { + const a = new Client(); + a.id_cli = "10"; + assertEquals(a.id_cli, "10"); +}); + +Deno.test("Set civ_cli correctement", () => { + const a = new Client(); + a.civ_cli = "Mme"; + assertEquals(a.civ_cli, "Mme"); +}); + +Deno.test("Set nom_cli correctement", () => { + const a = new Client(); + a.nom_cli = "Dupont"; + assertEquals(a.nom_cli, "Dupont"); +}); + +Deno.test("Set prenom_cli correctement", () => { + const a = new Client(); + a.prenom_cli = "Jean"; + assertEquals(a.prenom_cli, "Jean"); +}); + +Deno.test("Set tel_cli correctement", () => { + const a = new Client(); + a.tel_cli = "0123456789"; + assertEquals(a.tel_cli, "0123456789"); +}); + +Deno.test("Set mel_cli correctement", () => { + const a = new Client(); + a.mel_cli = "jean.dupont@example.com"; + assertEquals(a.mel_cli, "jean.dupont@example.com"); +}); + +Deno.test("Set adr_cli correctement", () => { + const a = new Client(); + a.adr_cli = "123 rue de la Paix"; + assertEquals(a.adr_cli, "123 rue de la Paix"); +}); + +Deno.test("Set cp_cli correctement", () => { + const a = new Client(); + a.cp_cli = "75001"; + assertEquals(a.cp_cli, "75001"); +}); + +Deno.test("Set commune_cli correctement", () => { + const a = new Client(); + a.commune_cli = "Paris"; + assertEquals(a.commune_cli, "Paris"); +}); + +Deno.test("Set tauxmax_remise_cli correctement", () => { + const a = new Client(); + a.tauxmax_remise_cli = "15"; + assertEquals(a.tauxmax_remise_cli, "15"); +}); + // Tests pour data_facture.ts Deno.test("Facture initialisation compléte correcte", () => { const facture = new Facture("8", "2021-05-01", "paiement différé", "5", "1", "EXPRES"); @@ -32,6 +166,96 @@ Deno.test("Facture initialisation compléte correcte", () => { assertEquals(facture.id_forfait, "EXPRES"); }); +// Tests des setters avec valeurs incorrectes + +Deno.test("Set num_fact négatif", () => { + const a = new Facture(); + assertThrows(() => a.num_fact = "-1", Error); +}); + +Deno.test("Set num_fact zéro", () => { + const a = new Facture(); + assertThrows(() => a.num_fact = "0", Error); +}); + +Deno.test("Set num_fact non entier", () => { + const a = new Facture(); + assertThrows(() => a.num_fact = "abc", Error); +}); + +Deno.test("Set date_fact invalide", () => { + const a = new Facture(); + assertThrows(() => a.date_fact = "invalid-date", Error); +}); + +Deno.test("Set taux_remise_fact négatif", () => { + const a = new Facture(); + assertThrows(() => a.taux_remise_fact = "-1", Error); +}); + +Deno.test("Set taux_remise_fact supérieur à 100", () => { + const a = new Facture(); + assertThrows(() => a.taux_remise_fact = "101", Error); +}); + +Deno.test("Set taux_remise_fact non numérique", () => { + const a = new Facture(); + assertThrows(() => a.taux_remise_fact = "abc", Error); +}); + +Deno.test("Set id_cli négatif", () => { + const a = new Facture(); + assertThrows(() => a.id_cli = "-1", Error); +}); + +Deno.test("Set id_cli zéro", () => { + const a = new Facture(); + assertThrows(() => a.id_cli = "0", Error); +}); + +Deno.test("Set id_cli non entier", () => { + const a = new Facture(); + assertThrows(() => a.id_cli = "abc", Error); +}); + +// Tests pour les setters de Facture + +Deno.test("Set num_fact correctement", () => { + const a = new Facture(); + a.num_fact = "10"; + assertEquals(a.num_fact, "10"); +}); + +Deno.test("Set date_fact correctement", () => { + const a = new Facture(); + a.date_fact = "2023-05-01"; + assertEquals(a.date_fact, "2023-05-01"); +}); + +Deno.test("Set comment_fact correctement", () => { + const a = new Facture(); + a.comment_fact = "Paiement comptant"; + assertEquals(a.comment_fact, "Paiement comptant"); +}); + +Deno.test("Set taux_remise_fact correctement", () => { + const a = new Facture(); + a.taux_remise_fact = "10"; + assertEquals(a.taux_remise_fact, "10"); +}); + +Deno.test("Set id_cli correctement", () => { + const a = new Facture(); + a.id_cli = "5"; + assertEquals(a.id_cli, "5"); +}); + +Deno.test("Set id_forfait correctement", () => { + const a = new Facture(); + a.id_forfait = "EXPRES"; + assertEquals(a.id_forfait, "EXPRES"); +}); + // Tests pour data_forfait.ts Deno.test("Forfait_livraison initialisation compléte correcte", () => { const forfait = new Forfait_livraison("livraison standard", "STD", "10"); @@ -40,6 +264,58 @@ Deno.test("Forfait_livraison initialisation compléte correcte", () => { assertEquals(forfait.mt_forfait, "10"); }); +// Tests des setters avec valeurs incorrectes + +Deno.test("Set lib_forfait trop court", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.lib_forfait = "test", Error); +}); + +Deno.test("Set id_forfait trop court", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.id_forfait = "AB", Error); +}); + +Deno.test("Set id_forfait trop long", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.id_forfait = "ABCDEFG", Error); +}); + +Deno.test("Set mt_forfait négatif", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.mt_forfait = "-1", Error); +}); + +Deno.test("Set mt_forfait zéro", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.mt_forfait = "0", Error); +}); + +Deno.test("Set mt_forfait non numérique", () => { + const a = new Forfait_livraison(); + assertThrows(() => a.mt_forfait = "abc", Error); +}); + +// Tests pour les setters de Forfait_livraison + +Deno.test("Set lib_forfait correctement", () => { + const a = new Forfait_livraison(); + a.lib_forfait = "Livraison standard"; + assertEquals(a.lib_forfait, "Livraison standard"); +}); + +Deno.test("Set id_forfait correctement", () => { + const a = new Forfait_livraison(); + a.id_forfait = "STD"; + assertEquals(a.id_forfait, "STD"); +}); + +Deno.test("Set mt_forfait correctement", () => { + const a = new Forfait_livraison(); + a.mt_forfait = "15.50"; + assertEquals(a.mt_forfait, "15.50"); +}); + //Tests pour data_ligne.ts Deno.test("Ligne initialisation compléte correcte", () => { @@ -49,6 +325,43 @@ Deno.test("Ligne initialisation compléte correcte", () => { assertEquals(ligne.qte_prod, "10"); }); +// Tests des setters avec valeurs incorrectes + +Deno.test("Set qte_prod négatif", () => { + const a = new Ligne(); + assertThrows(() => a.qte_prod = "-1", Error); +}); + +Deno.test("Set qte_prod zéro", () => { + const a = new Ligne(); + assertThrows(() => a.qte_prod = "0", Error); +}); + +Deno.test("Set qte_prod non entier", () => { + const a = new Ligne(); + assertThrows(() => a.qte_prod = "abc", Error); +}); + +// Tests pour les setters de Ligne + +Deno.test("Set num_fact correctement", () => { + const a = new Ligne(); + a.num_fact = "5"; + assertEquals(a.num_fact, "5"); +}); + +Deno.test("Set code_prod correctement", () => { + const a = new Ligne(); + a.code_prod = "ACQARMAP"; + assertEquals(a.code_prod, "ACQARMAP"); +}); + +Deno.test("Set qte_prod correctement", () => { + const a = new Ligne(); + a.qte_prod = "25"; + assertEquals(a.qte_prod, "25"); +}); + // Tests pour data_produits.ts Deno.test("Produit initialisation", () => { const produit = new Produit("HEALSIPO", "Healsio", "plate", "Portugal", "100", "1.90"); @@ -58,4 +371,99 @@ Deno.test("Produit initialisation", () => { assertEquals(produit.origine, "Portugal"); assertEquals(produit.conditionnement, "100"); assertEquals(produit.tarif_ht, "1.90"); +}); + +// Tests des setters avec valeurs incorrectes + +Deno.test("Set code_prod trop court", () => { + const a = new Produit(); + assertThrows(() => a.code_prod = "AB", Error); +}); + +Deno.test("Set code_prod trop long", () => { + const a = new Produit(); + assertThrows(() => a.code_prod = "ABCDEFGHI", Error); +}); + +Deno.test("Set lib_prod trop court", () => { + const a = new Produit(); + assertThrows(() => a.lib_prod = "AB", Error); +}); + +Deno.test("Set type invalide", () => { + const a = new Produit(); + assertThrows(() => a.type = "gazeuse", Error); +}); + +Deno.test("Set origine trop court", () => { + const a = new Produit(); + assertThrows(() => a.origine = "FR", Error); +}); + +Deno.test("Set conditionnement trop petit", () => { + const a = new Produit(); + assertThrows(() => a.conditionnement = "20", Error); +}); + +Deno.test("Set conditionnement trop grand", () => { + const a = new Produit(); + assertThrows(() => a.conditionnement = "201", Error); +}); + +Deno.test("Set conditionnement non entier", () => { + const a = new Produit(); + assertThrows(() => a.conditionnement = "abc", Error); +}); + +Deno.test("Set tarif_ht négatif", () => { + const a = new Produit(); + assertThrows(() => a.tarif_ht = "-1.00", Error); +}); + +Deno.test("Set tarif_ht zéro", () => { + const a = new Produit(); + assertThrows(() => a.tarif_ht = "0", Error); +}); + +Deno.test("Set tarif_ht non numérique", () => { + const a = new Produit(); + assertThrows(() => a.tarif_ht = "abc", Error); +}); + +// Tests pour les setters de Produit + +Deno.test("Set code_prod correctement", () => { + const a = new Produit(); + a.code_prod = "HEALSIPO"; + assertEquals(a.code_prod, "HEALSIPO"); +}); + +Deno.test("Set lib_prod correctement", () => { + const a = new Produit(); + a.lib_prod = "Healsio"; + assertEquals(a.lib_prod, "Healsio"); +}); + +Deno.test("Set type correctement", () => { + const a = new Produit(); + a.type = "plate"; + assertEquals(a.type, "plate"); +}); + +Deno.test("Set origine correctement", () => { + const a = new Produit(); + a.origine = "Portugal"; + assertEquals(a.origine, "Portugal"); +}); + +Deno.test("Set conditionnement correctement", () => { + const a = new Produit(); + a.conditionnement = "100"; + assertEquals(a.conditionnement, "100"); +}); + +Deno.test("Set tarif_ht correctement", () => { + const a = new Produit(); + a.tarif_ht = "1.90"; + assertEquals(a.tarif_ht, "1.90"); }); \ No newline at end of file