@@ -1053,6 +1053,56 @@ describe('Handler', () => {
10531053 } ) ;
10541054 } ) ;
10551055
1056+ describe ( 'handlePurgeState' , ( ) => {
1057+ const key = 'theKey' ;
1058+ const collection = '' ;
1059+
1060+ let expectedMsg ;
1061+
1062+ before ( ( ) => {
1063+ const payloadPb = new peer . PurgePrivateState ( ) ;
1064+ payloadPb . setKey ( key ) ;
1065+ payloadPb . setCollection ( collection ) ;
1066+ expectedMsg = mapToChaincodeMessage ( {
1067+ type : peer . ChaincodeMessage . Type . PURGE_PRIVATE_DATA ,
1068+ payload : payloadPb . serializeBinary ( ) ,
1069+ channel_id : 'theChannelID' ,
1070+ txid : 'theTxID'
1071+ } ) ;
1072+ } ) ;
1073+
1074+ afterEach ( ( ) => {
1075+ Handler = rewire ( '../../../fabric-shim/lib/handler.js' ) ;
1076+ sandbox . restore ( ) ;
1077+ } ) ;
1078+
1079+ it ( 'should resolve when _askPeerAndListen resolves' , async ( ) => {
1080+ const mockStream = { write : sinon . stub ( ) , end : sinon . stub ( ) } ;
1081+ const handler = new Handler . ChaincodeMessageHandler ( mockStream , mockChaincodeImpl ) ;
1082+ const _askPeerAndListenStub = sandbox . stub ( handler , '_askPeerAndListen' ) . resolves ( 'some response' ) ;
1083+
1084+ const result = await handler . handlePurgeState ( collection , key , 'theChannelID' , 'theTxID' ) ;
1085+
1086+ expect ( result ) . to . deep . equal ( 'some response' ) ;
1087+ expect ( _askPeerAndListenStub . firstCall . args . length ) . to . deep . equal ( 2 ) ;
1088+ expect ( _askPeerAndListenStub . firstCall . args [ 0 ] ) . to . deep . equal ( expectedMsg ) ;
1089+ expect ( _askPeerAndListenStub . firstCall . args [ 1 ] ) . to . deep . equal ( 'PurgePrivateState' ) ;
1090+ } ) ;
1091+
1092+ it ( 'should reject when _askPeerAndListen rejects' , async ( ) => {
1093+ const mockStream = { write : sinon . stub ( ) , end : sinon . stub ( ) } ;
1094+ const handler = new Handler . ChaincodeMessageHandler ( mockStream , mockChaincodeImpl ) ;
1095+ const _askPeerAndListenStub = sandbox . stub ( handler , '_askPeerAndListen' ) . rejects ( ) ;
1096+
1097+ const result = handler . handlePurgeState ( collection , key , 'theChannelID' , 'theTxID' ) ;
1098+
1099+ await expect ( result ) . to . eventually . be . rejected ;
1100+ expect ( _askPeerAndListenStub . firstCall . args . length ) . to . deep . equal ( 2 ) ;
1101+ expect ( _askPeerAndListenStub . firstCall . args [ 0 ] ) . to . deep . equal ( expectedMsg ) ;
1102+ expect ( _askPeerAndListenStub . firstCall . args [ 1 ] ) . to . deep . equal ( 'PurgePrivateState' ) ;
1103+ } ) ;
1104+ } ) ;
1105+
10561106 describe ( 'handlePutStateMetadata' , ( ) => {
10571107 const key = 'theKey' ;
10581108 const collection = '' ;
0 commit comments