@@ -469,7 +469,7 @@ describe('DocumentComposer', async () => {
469469 DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ;
470470 } ) ;
471471
472- it ( 'should throw error if `serviceEndpoint` is an array .' , ( ) => {
472+ it ( 'should allow an array as `serviceEndpoint`.' , ( ) => {
473473 const patch = {
474474 action : PatchAction . AddServices ,
475475 services : [ {
@@ -478,6 +478,20 @@ describe('DocumentComposer', async () => {
478478 serviceEndpoint : [ ]
479479 } ]
480480 } ;
481+
482+ // Expecting this call to succeed without errors.
483+ DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ;
484+ } ) ;
485+
486+ it ( 'should throw error if `serviceEndpoint` is an array that includes an array.' , ( ) => {
487+ const patch = {
488+ action : PatchAction . AddServices ,
489+ services : [ {
490+ id : 'someId' ,
491+ type : 'someType' ,
492+ serviceEndpoint : [ [ ] ] // array must contain URI strings or objects but not arrays
493+ } ]
494+ } ;
481495 const expectedError = new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointCannotBeAnArray ) ;
482496 expect ( ( ) => { DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ; } ) . toThrow ( expectedError ) ;
483497 } ) ;
@@ -495,6 +509,19 @@ describe('DocumentComposer', async () => {
495509 expect ( ( ) => { DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ; } ) . toThrow ( expectedError ) ;
496510 } ) ;
497511
512+ it ( 'should throw error if `serviceEndpoint` has an invalid type (inside an array).' , ( ) => {
513+ const patch = {
514+ action : PatchAction . AddServices ,
515+ services : [ {
516+ id : 'someId' ,
517+ type : 'someType' ,
518+ serviceEndpoint : [ 123 ] // Invalid serviceEndpoint type.
519+ } ]
520+ } ;
521+ const expectedError = new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject ) ;
522+ expect ( ( ) => { DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ; } ) . toThrow ( expectedError ) ;
523+ } ) ;
524+
498525 it ( 'Should throw if `serviceEndpoint` is not valid URI.' , ( ) => {
499526 const patch = {
500527 action : PatchAction . AddServices ,
@@ -510,6 +537,22 @@ describe('DocumentComposer', async () => {
510537 ErrorCode . DocumentComposerPatchServiceEndpointStringNotValidUri
511538 ) ;
512539 } ) ;
540+
541+ it ( 'Should throw if `serviceEndpoint` is not valid URI (inside an array).' , ( ) => {
542+ const patch = {
543+ action : PatchAction . AddServices ,
544+ services : [ {
545+ id : 'someId' ,
546+ type : 'someType' ,
547+ serviceEndpoint : [ 'http://' ] // Invalid URI.
548+ } ]
549+ } ;
550+
551+ JasmineSidetreeErrorValidator . expectSidetreeErrorToBeThrown (
552+ ( ) => DocumentComposer [ 'validateAddServicesPatch' ] ( patch ) ,
553+ ErrorCode . DocumentComposerPatchServiceEndpointStringNotValidUri
554+ ) ;
555+ } ) ;
513556 } ) ;
514557
515558 describe ( 'validateDocumentPatches()' , async ( ) => {
0 commit comments