Comparing version 0.2.7 to 0.2.8
@@ -200,3 +200,6 @@ class Masker { | ||
Object.keys(props).forEach(prop => { | ||
const Type = props[prop]; | ||
let Type = props[prop]; | ||
if (Array.isArray(Type)) { | ||
Type = Type[0]; | ||
} | ||
switch (Type) { | ||
@@ -203,0 +206,0 @@ case Object: |
{ | ||
"name": "carnaval", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -86,3 +86,3 @@ const Ajv = require('ajv').default; | ||
items: JSONSchema._toArrayItems(Type, rule) | ||
}, omit(rule, 'required', ...Object.keys(props))); | ||
}, omit(rule, 'required', 'enum', ...Object.keys(props))); | ||
} | ||
@@ -89,0 +89,0 @@ static _toArrayItems(Type, rule) { |
@@ -163,3 +163,3 @@ const test = require('ava'); | ||
return { | ||
names: {maxItems: 2} | ||
names: {maxItems: 2, enum: ['Shoes', 'Shirt', '12']} | ||
}; | ||
@@ -219,2 +219,12 @@ } | ||
test('validate array content error', t => { | ||
const json = {size: 'Medium', names: ['Shoe']}; | ||
const mapping = Mapping.map(Gift).afterDecode(object => validate(object)); | ||
return mapping.decode(json) | ||
.catch(error => { | ||
t.is(error.message, 'names/0 should be equal to one of the allowed values'); | ||
}); | ||
}); | ||
class Bookcase extends Domain { | ||
@@ -221,0 +231,0 @@ get props() { |
@@ -305,2 +305,41 @@ const test = require('ava'); | ||
class Garage extends Domain { | ||
get props() { | ||
return { | ||
boxes: [{ | ||
thing: Thing | ||
}] | ||
}; | ||
} | ||
} | ||
test('assign empty array deeply, touched & schema', t => { | ||
const mask = Mask.cover(Garage).except({ | ||
boxes: { | ||
thing: { | ||
name: false, | ||
description: false, | ||
size: false | ||
} | ||
} | ||
}); | ||
const physical = true; | ||
const garage = new Garage({boxes: []}); | ||
const touched = mask.settle( | ||
garage, | ||
new Garage({boxes: [{thing: new Thing({physical})}]}) | ||
); | ||
t.is(garage.boxes.length, 1); | ||
t.true(garage.boxes[0].thing instanceof Thing); | ||
t.is(garage.boxes[0].thing.name, undefined); | ||
t.is(garage.boxes[0].thing.description, undefined); | ||
t.is(garage.boxes[0].thing.size, undefined); | ||
t.is(garage.boxes[0].thing.physical, physical); | ||
t.is(touched.boxes, undefined); | ||
}); | ||
class Shipping extends Domain { | ||
@@ -307,0 +346,0 @@ get props() { |
119636
2962