Skip to content

Commit

Permalink
Merge pull request #10 from dionmaicon/verification_types_to_models
Browse files Browse the repository at this point in the history
Verification types to models
  • Loading branch information
dionmaicon committed Dec 13, 2019
2 parents 68910e4 + 54ce721 commit 25b2e2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion js/types.js
Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions test/types.test.js
Expand Up @@ -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"]
Expand All @@ -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++;
}
}
Expand Down Expand Up @@ -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();
});

0 comments on commit 25b2e2c

Please sign in to comment.