'use strict' ; import * as chai from 'chai' ; import * as sinonChai from 'sinon-chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import { BlockchainWalletExplorerProvider } from '../../extension/explorer/walletExplorer' ; import { BlockchainTreeItem } from '../../extension/explorer/model/BlockchainTreeItem' ; import { ExtensionUtil } from '../../extension/util/ExtensionUtil' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; module . exports = function ( ) : any { /**
     * Given
     */ this . Given ( "the '{string}' wallet" , this . timeout , async ( wallet ) => { this . wallet = wallet ; } ) ; this . Given ( "the '{string}' identity" , this . timeout , async ( identity ) => { if ( identity === 'Local Fabric Admin' ) { identity = 'Org1 Admin' ; } this . identity = identity ; } ) ; this . Given ( /the identity '(\S*?)'(?: with attributes )?'?(\S*?)?'? exists$/ , this . timeout , async ( identity , attributes ) => { await this . walletAndIdentityHelper . createCAIdentity ( this . wallet , identity , this . environmentName , attributes ) ; this . identity = identity ; } ) ; this . Given ( /the wallet '(.*?)' with identity '(.*?)' and mspid '(.*?)' exists/ , this . timeout , async ( wallet , identity , mspid ) => { const method = process . env . OPSTOOLS_FABRIC ? 'JSON file' : 'certs' ; const blockchainWalletExplorerProvider = ExtensionUtil . getBlockchainWalletExplorerProvider ( ) ; let treeItems = await blockchainWalletExplorerProvider . getChildren ( ) ; const walletIndex = treeItems . findIndex ( ( item ) => { return item . label === wallet ; } ) ; if ( walletIndex < 0 ) { await this . walletAndIdentityHelper . createWallet ( wallet , identity , mspid , method ) ; } else { treeItems = await blockchainWalletExplorerProvider . getChildren ( treeItems [ walletIndex ] ) ; const identityExists = treeItems . find ( ( item ) => { return item . label === identity ; } ) ; if ( ! identityExists ) { await this . walletAndIdentityHelper . createIdentity ( wallet , identity , mspid , method ) ; } } this . wallet = wallet ; this . identity = identity ; } ) ; /**
     * When
     */ this . When ( /^I create a wallet '(.*?)' using (certs|enrollId|JSON file) with identity name '(.*?)' and mspid '(.*?)'$/ , this . timeout , async ( wallet , method , identityName , mspid ) => { await this . walletAndIdentityHelper . createWallet ( wallet , identityName , mspid , method ) ; } ) ; this . When ( /^I create an identity using (certs|enrollId|JSON file) with identity name '(.*?)' and mspid '(.*?)' in wallet '(.*?)'$/ , this . timeout , async ( method , identityName , mspid , wallet ) => { await this . walletAndIdentityHelper . createIdentity ( wallet , identityName , mspid , method ) ; } ) ; this . When ( /I register a new identity '(.*?)' (?:with the attributes)? '(.*?)'?$/ , this . timeout , async ( identity , attributes ) => { await this . walletAndIdentityHelper . createCAIdentity ( this . wallet , identity , this . environmentName , attributes ) ; } ) ; this . When ( /I delete the identity '(.*?)'$/ , this . timeout , async ( identity ) => { await this . walletAndIdentityHelper . deleteCAIdentity ( identity , this . wallet , this . environmentName ) ; } ) ; } ;