@@ -1108,26 +1108,19 @@ describe('Stub', () => {
11081108
11091109 beforeEach ( ( ) => {
11101110 stub = new Stub ( {
1111- handleGetState : sinon . stub ( ) . resolves ( Buffer . from ( 'value' ) )
1111+ handleGetMultipleStates : sinon . stub ( ) . resolves ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] )
11121112 } , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
11131113 } ) ;
11141114
11151115 it ( 'should throw an error if keys is not an array' , async ( ) => {
11161116 await expect ( stub . getMultipleStates ( 'not-an-array' ) ) . to . be . rejectedWith ( / k e y s m u s t b e a n a r r a y o f s t r i n g s / ) ;
11171117 } ) ;
11181118
1119- it ( 'should call getState for each key and return the results' , async ( ) => {
1120- sandbox . stub ( stub , 'getState' ) . callsFake ( async ( key ) => {
1121- if ( key === 'key1' ) {
1122- return Buffer . from ( 'value1' ) ;
1123- } else if ( key === 'key2' ) {
1124- return Buffer . from ( 'value2' ) ;
1125- }
1126- } ) ;
1127-
1119+ it ( 'should call call handleGetMultipleStates on the handler and return the results' , async ( ) => {
11281120 const results = await stub . getMultipleStates ( [ 'key1' , 'key2' ] ) ;
11291121 expect ( results ) . to . deep . equal ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] ) ;
1130- sinon . assert . calledTwice ( stub . getState ) ;
1122+ sinon . assert . calledOnce ( stub . handler . handleGetMultipleStates ) ;
1123+ sinon . assert . calledWith ( stub . handler . handleGetMultipleStates , [ 'key1' , 'key2' ] , 'dummyChannelId' , 'dummyTxid' ) ;
11311124 } ) ;
11321125 } ) ;
11331126
@@ -1136,7 +1129,7 @@ describe('Stub', () => {
11361129
11371130 beforeEach ( ( ) => {
11381131 stub = new Stub ( {
1139- handleGetState : sinon . stub ( ) . resolves ( Buffer . from ( 'value' ) )
1132+ handleGetMultiplePrivateData : sinon . stub ( ) . resolves ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] )
11401133 } , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
11411134 } ) ;
11421135
@@ -1148,18 +1141,11 @@ describe('Stub', () => {
11481141 await expect ( stub . getMultiplePrivateData ( 'collection' , 'not-an-array' ) ) . to . be . rejectedWith ( / k e y s m u s t b e a n a r r a y o f s t r i n g s / ) ;
11491142 } ) ;
11501143
1151- it ( 'should call getPrivateData for each key and return the results' , async ( ) => {
1152- sandbox . stub ( stub , 'getPrivateData' ) . callsFake ( async ( collection , key ) => {
1153- if ( key === 'key1' ) {
1154- return Buffer . from ( 'value1' ) ;
1155- } else if ( key === 'key2' ) {
1156- return Buffer . from ( 'value2' ) ;
1157- }
1158- } ) ;
1159-
1144+ it ( 'should call handleGetMultiplePrivateData on the handler and return the results' , async ( ) => {
11601145 const results = await stub . getMultiplePrivateData ( 'collection' , [ 'key1' , 'key2' ] ) ;
11611146 expect ( results ) . to . deep . equal ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] ) ;
1162- sinon . assert . calledTwice ( stub . getPrivateData ) ;
1147+ sinon . assert . calledOnce ( stub . handler . handleGetMultiplePrivateData ) ;
1148+ sinon . assert . calledWith ( stub . handler . handleGetMultiplePrivateData , 'collection' , [ 'key1' , 'key2' ] , 'dummyChannelId' , 'dummyTxid' ) ;
11631149 } ) ;
11641150 } ) ;
11651151
0 commit comments