@@ -411,6 +411,7 @@ test('support object with array $ref', t => {
411411 t . is ( properties [ 0 ] . label , 'root' ) ;
412412 t . deepEqual ( properties [ 0 ] . schema , schema . definitions . root . items as JsonSchema ) ;
413413} ) ;
414+
414415test ( 'containment properties add when array not defined' , t => {
415416 const schema = t . context . fooBarArraySchema ;
416417 const service : SchemaService = new SchemaServiceImpl ( schema ) ;
@@ -424,6 +425,38 @@ test('containment properties add when array not defined', t => {
424425 t . is ( data . foo . length , 1 ) ;
425426 t . is ( data . foo [ 0 ] , valueToAdd ) ;
426427} ) ;
428+
429+ test ( 'containment properties add when array not defined and generate ID' , t => {
430+ const schema = {
431+ type : 'object' ,
432+ properties : {
433+ foo : {
434+ type : 'array' ,
435+ items : {
436+ type : 'object' ,
437+ properties : {
438+ _id : { type : 'string' } ,
439+ bar : { type : 'string' }
440+ }
441+ }
442+ }
443+ }
444+ } ;
445+
446+ const service : SchemaService = new SchemaServiceImpl ( schema )
447+ . setIdentifyingProp ( '_id' ) ;
448+ const property = service . getContainmentProperties ( schema ) [ 0 ] ;
449+ const data = {
450+ foo : undefined
451+ } ;
452+ const valueToAdd = { bar : `Hey Mum, look, it's an idea` } ;
453+ property . addToData ( data ) ( valueToAdd ) ;
454+
455+ t . true ( data . foo !== undefined ) ;
456+ t . is ( data . foo . length , 1 ) ;
457+ t . true ( data . foo [ 0 ] . _id !== undefined ) ;
458+ } ) ;
459+
427460test ( 'containment properties add when array defined' , t => {
428461 const schema = t . context . fooBarArraySchema ;
429462 const service : SchemaService = new SchemaServiceImpl ( schema ) ;
@@ -435,6 +468,7 @@ test('containment properties add when array defined', t => {
435468 t . is ( data . foo . length , 2 ) ;
436469 t . is ( data . foo [ 1 ] , valueToAdd ) ;
437470} ) ;
471+
438472test ( 'containment properties add default with existing neighbour' , t => {
439473 // expectation default === add after neighbour
440474 const schema = t . context . fooBarArraySchema ;
@@ -451,6 +485,7 @@ test('containment properties add default with existing neighbour', t => {
451485 t . is ( data . foo [ 1 ] , valueToAdd ) ;
452486 t . is ( data . foo [ 2 ] , lastValue ) ;
453487} ) ;
488+
454489test ( 'containment properties add after existing neighbour(not last in array)' , t => {
455490 const schema = t . context . fooBarArraySchema ;
456491 const service : SchemaService = new SchemaServiceImpl ( schema ) ;
0 commit comments