text: /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  'use strict';
  /**
   * Write the unit tests for your transction processor functions here
   */
  
  const AdminConnection = require('composer-admin').AdminConnection;
  const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
  const { BusinessNetworkDefinition, CertificateUtil, IdCard } = require('composer-common');
  const path = require('path');
  
  const chai = require('chai');
  chai.should();
  chai.use(require('chai-as-promised'));
  
  const namespace = 'org.callforcode.biznet';
  const assetType = 'NFCAsset';
  const assetNS = namespace + '.' + assetType;
  const participantType = 'Party';
  const participantNS = namespace + '.' + participantType;
  
  describe('#' + namespace, () => {
      // In-memory card store for testing so cards are not persisted to the file system
      const cardStore = require('composer-common').NetworkCardStoreManager.getCardStore( { type: 'composer-wallet-inmemory' } );
  
      // Embedded connection used for local testing
      const connectionProfile = {
          name: 'embedded',
          'x-type': 'embedded'
      };
  
      // Name of the business network card containing the administrative identity for the business network
      const adminCardName = 'admin';
  
      // Admin connection to the blockchain, used to deploy the business network
      let adminConnection;
  
      // This is the business network connection the tests will use.
      let businessNetworkConnection;
  
      // This is the factory for creating instances of types.
      let factory;
  
      // These are the identities for Alice and Bob.
      const aliceCardName = 'RedCross';
      const bobCardName = 'Surviver1';
  
      // These are a list of receieved events.
      let events;
  
      let businessNetworkName;
  
      before(async () => {
          // Generate certificates for use with the embedded connection
          const credentials = CertificateUtil.generate({ commonName: 'admin' });
  
          // Identity used with the admin connection to deploy business networks
          const deployerMetadata = {
              version: 1,
              userName: 'PeerAdmin',
              roles: [ 'PeerAdmin', 'ChannelAdmin' ]
          };
          const deployerCard = new IdCard(deployerMetadata, connectionProfile);
          deployerCard.setCredentials(credentials);
          const deployerCardName = 'PeerAdmin';
  
          adminConnection = new AdminConnection({ cardStore: cardStore });
  
          await adminConnection.importCard(deployerCardName, deployerCard);
          await adminConnection.connect(deployerCardName);
      });
  
      /**
       *
       * @param {String} cardName The card name to use for this identity
       * @param {Object} identity The identity details
       */
      async function importCardForIdentity(cardName, identity) {
          const metadata = {
              userName: identity.userID,
              version: 1,
              enrollmentSecret: identity.userSecret,
              businessNetwork: businessNetworkName
          };
          const card = new IdCard(metadata, connectionProfile);
          await adminConnection.importCard(cardName, card);
      }
  
      // This is called before each test is executed.
      beforeEach(async () => {
          // Generate a business network definition from the project directory.
          let businessNetworkDefinition = await BusinessNetworkDefinition.fromDirectory(path.resolve(__dirname, '..'));
          businessNetworkName = businessNetworkDefinition.getName();
          await adminConnection.install(businessNetworkDefinition);
          const startOptions = {
              networkAdmins: [
                  {
                      userName: 'admin',
                      enrollmentSecret: 'adminpw'
                  }
              ]
          };
          const adminCards = await adminConnection.start(businessNetworkName, businessNetworkDefinition.getVersion(), startOptions);
          await adminConnection.importCard(adminCardName, adminCards.get('admin'));
  
          // Create and establish a business network connection
          businessNetworkConnection = new BusinessNetworkConnection({ cardStore: cardStore });
          events = [];
          businessNetworkConnection.on('event', event => {
              events.push(event);
          });
          await businessNetworkConnection.connect(adminCardName);
  
          // Get the factory for the business network.
          factory = businessNetworkConnection.getBusinessNetwork().getFactory();
  
          const participantRegistry = await businessNetworkConnection.getParticipantRegistry(participantNS);
          // Create the participants.
          const RedCross = factory.newResource(namespace, participantType, 'RedCross');
          RedCross.partyId = 'RedCross';
          RedCross.name = 'RedCross';
  
          const Surviver1 = factory.newResource(namespace, participantType, 'Surviver1');
          Surviver1.partyId = 'Surviver1';
          Surviver1.name = 'Abdul';
  
          participantRegistry.addAll([RedCross, Surviver1]);
  
      });
  
  });
  
  