@@ -256,7 +256,7 @@ describe('document content', function(){
256256 done ( ) ;
257257 } ) ) ;
258258 } ) ;
259- it ( 'should write a binary descriptor with a ReadableStream ' , function ( done ) {
259+ it ( 'should write a binary descriptor with a Readable stream ' , function ( done ) {
260260 this . timeout ( 3000 ) ;
261261 var uri = '/test/write/stream1.png' ;
262262 var readableBinary = new ValueStream ( binaryValue ) ;
@@ -440,6 +440,22 @@ describe('document metadata', function(){
440440 } ,
441441 quality : 1 ,
442442 content : { key1 : 'value 1' }
443+ } ,
444+ { contentType : 'application/json' ,
445+ collections : [ 'collectionDefault/0' , 'collectionDefault/1' ] ,
446+ permissions : [
447+ { 'role-name' :'app-user' , capabilities :[ 'read' ] } ,
448+ { 'role-name' :'app-builder' , capabilities :[ 'read' , 'update' ] }
449+ ] ,
450+ properties : {
451+ propertyDefault1 : 'default property value 1' ,
452+ propertyDefault2 : 'default property value 2'
453+ } ,
454+ quality : 2
455+ } ,
456+ { uri : '/test/write/metaContent2.json' ,
457+ contentType : 'application/json' ,
458+ content : { key2 : 'value 2' }
443459 } ) .
444460 result ( function ( response ) { done ( ) ; } , done ) ;
445461 } ) ;
@@ -480,6 +496,43 @@ describe('document metadata', function(){
480496 done ( ) ;
481497 } , done ) ;
482498 } ) ;
499+ it ( 'should read back default metadata and content' , function ( done ) {
500+ db . read ( { uris :'/test/write/metaContent2.json' , categories :[ 'metadata' , 'content' ] } ) .
501+ result ( function ( documents ) {
502+ valcheck . isUndefined ( documents ) . should . equal ( false ) ;
503+ documents . length . should . equal ( 1 ) ;
504+ var document = documents [ 0 ] ;
505+ document . collections . length . should . equal ( 2 ) ;
506+ for ( var i = 0 ; i < 2 ; i ++ ) {
507+ document . collections [ i ] . should . equal ( 'collectionDefault/' + i ) ;
508+ }
509+ var permissionsFound = 0 ;
510+ document . permissions . forEach ( function ( permission ) {
511+ switch ( permission [ 'role-name' ] ) {
512+ case 'app-user' :
513+ permissionsFound ++ ;
514+ permission . capabilities . length . should . equal ( 1 ) ;
515+ permission . capabilities [ 0 ] . should . equal ( 'read' ) ;
516+ break ;
517+ case 'app-builder' :
518+ permissionsFound ++ ;
519+ permission . capabilities . length . should . equal ( 2 ) ;
520+ permission . capabilities . should . containEql ( 'read' ) ;
521+ permission . capabilities . should . containEql ( 'update' ) ;
522+ break ;
523+ }
524+ } ) ;
525+ permissionsFound . should . equal ( 2 ) ;
526+ document . should . have . property ( 'properties' ) ;
527+ document . properties . should . have . property ( 'propertyDefault1' ) ;
528+ document . properties . propertyDefault1 . should . equal ( 'default property value 1' ) ;
529+ document . properties . should . have . property ( 'propertyDefault2' ) ;
530+ document . properties . propertyDefault2 . should . equal ( 'default property value 2' ) ;
531+ document . quality . should . equal ( 2 ) ;
532+ document . content . key2 . should . equal ( 'value 2' ) ;
533+ done ( ) ;
534+ } , done ) ;
535+ } ) ;
483536 } ) ;
484537 describe ( 'without content' , function ( ) {
485538 before ( function ( done ) {
@@ -498,19 +551,19 @@ describe('document metadata', function(){
498551 } ) .
499552 result ( function ( response ) { done ( ) ; } , done ) ;
500553 } ) ;
501- it ( 'should read back the metadata' , function ( done ) {
554+ it ( 'should read back the all of the metadata' , function ( done ) {
502555 db . read ( { uris :'/test/write/metaContent1.json' , categories :'metadata' } ) .
503556 result ( function ( documents ) {
504557 valcheck . isUndefined ( documents ) . should . equal ( false ) ;
505558 documents . length . should . equal ( 1 ) ;
506559 var document = documents [ 0 ] ;
507560 valcheck . isUndefined ( document ) . should . equal ( false ) ;
508- valcheck . isUndefined ( document . collections ) . should . equal ( false ) ;
561+ document . should . have . property ( 'collections' ) ;
509562 document . collections . length . should . equal ( 2 ) ;
510563 for ( var i = 0 ; i < 2 ; i ++ ) {
511564 document . collections [ i ] . should . equal ( 'collection2/' + i ) ;
512565 }
513- valcheck . isUndefined ( document . permissions ) . should . equal ( false ) ;
566+ document . should . have . property ( 'permissions' ) ;
514567 var permissionsFound = 0 ;
515568 document . permissions . forEach ( function ( permission ) {
516569 switch ( permission [ 'role-name' ] ) {
@@ -539,6 +592,76 @@ describe('document metadata', function(){
539592 done ( ) ;
540593 } , done ) ;
541594 } ) ;
595+ it ( 'should read back collections metadata' , function ( done ) {
596+ db . read ( { uris :'/test/write/metaContent1.json' , categories :'collections' } ) .
597+ result ( function ( documents ) {
598+ valcheck . isUndefined ( documents ) . should . equal ( false ) ;
599+ documents . length . should . equal ( 1 ) ;
600+ var document = documents [ 0 ] ;
601+ document . should . have . property ( 'collections' ) ;
602+ document . collections . length . should . equal ( 2 ) ;
603+ for ( var i = 0 ; i < 2 ; i ++ ) {
604+ document . collections [ i ] . should . equal ( 'collection2/' + i ) ;
605+ }
606+ document . should . not . have . property ( 'content' ) ;
607+ done ( ) ;
608+ } , done ) ;
609+ } ) ;
610+ it ( 'should read back permissions metadata' , function ( done ) {
611+ db . read ( { uris :'/test/write/metaContent1.json' , categories :'permissions' } ) .
612+ result ( function ( documents ) {
613+ valcheck . isUndefined ( documents ) . should . equal ( false ) ;
614+ documents . length . should . equal ( 1 ) ;
615+ var document = documents [ 0 ] ;
616+ document . should . have . property ( 'permissions' ) ;
617+ var permissionsFound = 0 ;
618+ document . permissions . forEach ( function ( permission ) {
619+ switch ( permission [ 'role-name' ] ) {
620+ case 'app-user' :
621+ permissionsFound ++ ;
622+ permission . capabilities . length . should . equal ( 2 ) ;
623+ permission . capabilities . should . containEql ( 'read' ) ;
624+ permission . capabilities . should . containEql ( 'update' ) ;
625+ break ;
626+ case 'app-builder' :
627+ permissionsFound ++ ;
628+ permission . capabilities . length . should . equal ( 1 ) ;
629+ permission . capabilities [ 0 ] . should . equal ( 'execute' ) ;
630+ break ;
631+ }
632+ } ) ;
633+ permissionsFound . should . equal ( 2 ) ;
634+ document . should . not . have . property ( 'content' ) ;
635+ done ( ) ;
636+ } , done ) ;
637+ } ) ;
638+ it ( 'should read back the properties metadata' , function ( done ) {
639+ db . read ( { uris :'/test/write/metaContent1.json' , categories :'properties' } ) .
640+ result ( function ( documents ) {
641+ valcheck . isUndefined ( documents ) . should . equal ( false ) ;
642+ documents . length . should . equal ( 1 ) ;
643+ var document = documents [ 0 ] ;
644+ document . should . have . property ( 'properties' ) ;
645+ document . properties . should . have . property ( 'property1' ) ;
646+ document . properties . property1 . should . equal ( 'property value 1' ) ;
647+ document . properties . should . have . property ( 'property2' ) ;
648+ document . properties . property2 . should . equal ( 'property value 2' ) ;
649+ document . should . not . have . property ( 'content' ) ;
650+ done ( ) ;
651+ } , done ) ;
652+ } ) ;
653+ it ( 'should read back the quality metadata' , function ( done ) {
654+ db . read ( { uris :'/test/write/metaContent1.json' , categories :'quality' } ) .
655+ result ( function ( documents ) {
656+ valcheck . isUndefined ( documents ) . should . equal ( false ) ;
657+ documents . length . should . equal ( 1 ) ;
658+ var document = documents [ 0 ] ;
659+ document . should . have . property ( 'quality' ) ;
660+ document . quality . should . equal ( 2 ) ;
661+ document . should . not . have . property ( 'content' ) ;
662+ done ( ) ;
663+ } , done ) ;
664+ } ) ;
542665 } ) ;
543666 } ) ;
544667} ) ;
0 commit comments