@allbin/entity-logic
Advanced tools
Comparing version 0.6.4 to 0.7.0
@@ -313,5 +313,41 @@ "use strict"; | ||
} | ||
var invalid = false; | ||
var prev_val = prev_properties[p]; | ||
var prop_val = properties[p]; | ||
if (prev_val !== prop_val) { | ||
switch (schema_prop.type) { | ||
case 'array:number': | ||
case 'array:string': { | ||
var prev_is_array = Array.isArray(prev_val); | ||
var prop_is_array = Array.isArray(prop_val); | ||
if (prev_is_array !== prop_is_array) { | ||
invalid = true; | ||
} | ||
if (!!prev_val !== !!prop_val) { | ||
invalid = true; | ||
} | ||
if (Array.isArray(prev_val) && Array.isArray(prop_val)) { | ||
if (prev_val.length !== prop_val.length) { | ||
invalid = true; | ||
} | ||
for (var i = 0; i < prev_val.length; i++) { | ||
if (prev_val[i] !== prop_val[i]) { | ||
invalid = true; | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
case 'boolean': | ||
case 'number': | ||
case 'string': | ||
case 'date': | ||
case 'photo': | ||
case 'location': { | ||
if (prev_val !== prop_val) { | ||
invalid = true; | ||
} | ||
break; | ||
} | ||
} | ||
if (invalid) { | ||
throw new Error("Properties include modification to readonly property " + p); | ||
@@ -318,0 +354,0 @@ } |
@@ -74,2 +74,12 @@ "use strict"; | ||
}, | ||
{ | ||
key: 'inventory.10', | ||
type: 'string', | ||
name: 'string-readonly', | ||
}, | ||
{ | ||
key: 'inventory.11', | ||
type: 'array:string', | ||
name: 'arraystring-readonly', | ||
}, | ||
], | ||
@@ -1175,3 +1185,3 @@ }; | ||
}); | ||
it('correctly validates modifiable properties', function () { | ||
it('correctly validates modifiable single properties (pos)', function () { | ||
var prev_props = { | ||
@@ -1188,2 +1198,38 @@ 'inventory.3': 'something', | ||
}); | ||
it('correctly validates modifiable single properties (neg)', function () { | ||
var prev_props = { | ||
'inventory.10': 'test', | ||
}; | ||
var props = { | ||
'inventory.10': 'test2', | ||
}; | ||
var logic = (0, index_1.EntityLogic)(schema); | ||
expect(function () { | ||
return logic.validatePropertiesModifiable(prev_props, props); | ||
}).toThrow(); | ||
}); | ||
it('correctly validates modifiable array properties (pos)', function () { | ||
var prev_props = { | ||
'inventory.11': ['test', 'test2'], | ||
}; | ||
var props = { | ||
'inventory.11': ['test', 'test2'], | ||
}; | ||
var logic = (0, index_1.EntityLogic)(schema); | ||
expect(function () { | ||
return logic.validatePropertiesModifiable(prev_props, props); | ||
}).not.toThrow(); | ||
}); | ||
it('correctly validates modifiable array properties (neg)', function () { | ||
var prev_props = { | ||
'inventory.11': ['test', 'test2'], | ||
}; | ||
var props = { | ||
'inventory.11': ['test2', 'test'], | ||
}; | ||
var logic = (0, index_1.EntityLogic)(schema); | ||
expect(function () { | ||
return logic.validatePropertiesModifiable(prev_props, props); | ||
}).toThrow(); | ||
}); | ||
}); |
{ | ||
"name": "@allbin/entity-logic", | ||
"version": "0.6.4", | ||
"version": "0.7.0", | ||
"description": "Logic solver for mobilix filters", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85488
2311