@@ -68,6 +68,7 @@ describe('BusinessNetworkConnection', () => {
6868 mockConnection = sinon . createStubInstance ( Connection ) ;
6969 mockSecurityContext . getConnection . returns ( mockConnection ) ;
7070 mockBusinessNetworkDefinition = sinon . createStubInstance ( BusinessNetworkDefinition ) ;
71+ mockBusinessNetworkDefinition . getName . returns ( 'super-doge-network' ) ;
7172 businessNetworkConnection = new BusinessNetworkConnection ( ) ;
7273 businessNetworkConnection . businessNetwork = mockBusinessNetworkDefinition ;
7374 modelManager = new ModelManager ( ) ;
@@ -1146,6 +1147,45 @@ describe('BusinessNetworkConnection', () => {
11461147 } ) ;
11471148 } ) ;
11481149
1150+ it ( 'should throw an error if the identity exists in the registry and connection is requires registry check' , ( ) => {
1151+ mockConnection . registryCheckRequired . returns ( true ) ;
1152+
1153+ let identityRegistry = sinon . createStubInstance ( IdentityRegistry ) ;
1154+ identityRegistry . getAll . resolves ( [ { name : 'dogeid1' } ] ) ;
1155+ sandbox . stub ( IdentityRegistry , 'getIdentityRegistry' ) . resolves ( identityRegistry ) ;
1156+
1157+ return businessNetworkConnection . issueIdentity ( 'org.acme.sample.SampleParticipant#dogeid1' , 'dogeid1' )
1158+ . catch ( ( error ) => {
1159+ error . should . match ( / I d e n t i t y w i t h n a m e d o g e i d 1 a l r e a d y e x i s t s i n s u p e r - d o g e - n e t w o r k / ) ;
1160+ } ) ;
1161+ } ) ;
1162+
1163+ it ( 'should submit a request to the chaincode if the identity does not exist in the registry and connection is WebConnection' , ( ) => {
1164+ mockConnection . registryCheckRequired . returns ( true ) ;
1165+
1166+ let identityRegistry = sinon . createStubInstance ( IdentityRegistry ) ;
1167+ identityRegistry . getAll . resolves ( [ { name : 'dogeid0' } ] ) ;
1168+ sandbox . stub ( IdentityRegistry , 'getIdentityRegistry' ) . resolves ( identityRegistry ) ;
1169+
1170+ sandbox . stub ( businessNetworkConnection , 'submitTransaction' ) . resolves ( ) ;
1171+
1172+ return businessNetworkConnection . issueIdentity ( 'org.acme.sample.SampleParticipant#dogeid1' , 'dogeid1' )
1173+ . then ( ( result ) => {
1174+ sinon . assert . calledOnce ( mockConnection . createIdentity ) ;
1175+ sinon . assert . calledWith ( mockConnection . createIdentity , mockSecurityContext , 'dogeid1' ) ;
1176+ sinon . assert . calledOnce ( businessNetworkConnection . submitTransaction ) ;
1177+ const tx = businessNetworkConnection . submitTransaction . args [ 0 ] [ 0 ] ;
1178+ tx . instanceOf ( 'org.hyperledger.composer.system.IssueIdentity' ) . should . be . true ;
1179+ tx . participant . isRelationship ( ) . should . be . true ;
1180+ tx . participant . getFullyQualifiedIdentifier ( ) . should . equal ( 'org.acme.sample.SampleParticipant#dogeid1' ) ;
1181+ tx . identityName . should . equal ( 'dogeid1' ) ;
1182+ result . should . deep . equal ( {
1183+ userID : 'dogeid1' ,
1184+ userSecret : 'suchsecret'
1185+ } ) ;
1186+ } ) ;
1187+ } ) ;
1188+
11491189 it ( 'should submit a request to the chaincode for a fully qualified identifier' , ( ) => {
11501190 sandbox . stub ( businessNetworkConnection , 'submitTransaction' ) . resolves ( ) ;
11511191 return businessNetworkConnection . issueIdentity ( 'org.acme.sample.SampleParticipant#dogeid1' , 'dogeid1' )
0 commit comments