From 77079565711805e20158c42765cb5f2a710ab843 Mon Sep 17 00:00:00 2001 From: "Dion Maicon E. Duarte" Date: Thu, 12 Dec 2019 21:00:04 -0200 Subject: [PATCH 1/2] Add types verification fix code smell --- test/types.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/types.test.js b/test/types.test.js index c6248f2..770f35f 100644 --- a/test/types.test.js +++ b/test/types.test.js @@ -53,7 +53,7 @@ test("Check if types are valid", () => { }); test("Check if Types Models is invalid", () => { - let model = { + let person = { sponsor: { type: "selects", options: ["Patron", "Vue-Crudgen"] @@ -62,9 +62,9 @@ test("Check if Types Models is invalid", () => { let count; - for (let prop in model) { - if (model.hasOwnProperty(prop)) { - if (Types.isValid(model[prop].type)) { + for (let prop in person) { + if (person.hasOwnProperty(prop)) { + if (Types.isValid(person[prop].type)) { count++; } } From 54ce721af72bdaa57df3eb840b5d773320c6bc3d Mon Sep 17 00:00:00 2001 From: "Dion Maicon E. Duarte" Date: Thu, 12 Dec 2019 22:05:49 -0200 Subject: [PATCH 2/2] Uncovered lines test fix --- js/types.js | 7 ++++++- test/types.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/js/types.js b/js/types.js index 6c7cd91..5e2f00d 100644 --- a/js/types.js +++ b/js/types.js @@ -106,7 +106,12 @@ const Types = class { }; for (let prop in model) { - if (!model.hasOwnProperty(prop)) continue; + if (!model.hasOwnProperty(prop)) { + response.message = "Model invalid."; + response.success = false; + continue; + } + let object = model[prop]; switch (model[prop].type) { case Types.ONE_TO_ONE: diff --git a/test/types.test.js b/test/types.test.js index 770f35f..9f66a6c 100644 --- a/test/types.test.js +++ b/test/types.test.js @@ -220,3 +220,13 @@ test("Check if model is invalid (INVALID TYPE)", () => { expect(response.success).toBeFalsy(); }); + +test("Check if model is invalid (Model Inherited)", () => { + const obj = Object.create({ name: "stuart" }); + + let response = Types.modelIsValid(obj); + + expect(response.message).toMatch("Model invalid."); + + expect(response.success).toBeFalsy(); +});