Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Don't generate LoopBack models for enums (contributes to #4094) (#4154)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Stone <[email protected]>
  • Loading branch information
Simon Stone authored and mbwhite committed Jun 14, 2018
1 parent ac0f643 commit 26ef1b6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ rm -rf ./my-bus-net # a business network created from generator
rm -rf ./tutorial-network # business network created from generator in dev tut
rm -f ./networkadmin.card
rm -f ./composer-report-*
rm -rf ./my-angular-app
rm -rf ./my-loopback-app

# remove anything already there
Expand Down Expand Up @@ -217,6 +218,7 @@ for INTEST in $(echo ${INTEST} | tr "," " "); do
rm -rf ${HOME}/.npmrc
rm -f ./networkadmin.card
rm -f ./composer-report-*
rm -rf ./my-angular-app
rm -rf ./my-loopback-app
if [ "${DOCKER_FILE}" != "" ]; then
cd ../composer-runtime-hlfv1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ const optionOrPrompt = require('yeoman-option-or-prompt');
const Util = require('../util');
const version = require('../../package.json').version;
const yeoman = require('yeoman-generator');

let businessNetworkConnectionOptions = undefined;

module.exports = class extends yeoman.Base {

/**
* Set the business network connection options.
* @param {*} options The business network connection options.
*/
static setBusinessNetworkConnectionOptions(options) {
businessNetworkConnectionOptions = options;
}

/**
* Constructor.
*/
Expand Down Expand Up @@ -158,7 +169,7 @@ module.exports = class extends yeoman.Base {

// Get the business network definition.
if (this.liveNetwork) {
const businessNetworkConnection = new BusinessNetworkConnection();
const businessNetworkConnection = new BusinessNetworkConnection(businessNetworkConnectionOptions);
this.businessNetworkDefinition = await businessNetworkConnection.connect(this.cardName);
await businessNetworkConnection.disconnect();
} else {
Expand All @@ -174,7 +185,8 @@ module.exports = class extends yeoman.Base {
const classDeclarations = introspector.getClassDeclarations().filter((classDeclaration) => {
return !classDeclaration.isAbstract() &&
!classDeclaration.isSystemType() &&
!classDeclaration.isEvent();
!classDeclaration.isEvent() &&
!classDeclaration.isEnum();
});

// Copy the skeleton project into place.
Expand Down
Binary file modified packages/generator-hyperledger-composer/test/data/carAuction.bna
Binary file not shown.
72 changes: 48 additions & 24 deletions packages/generator-hyperledger-composer/test/loopback.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
const { AdminConnection } = require('composer-admin');
const assert = require('yeoman-assert');
const fs = require('fs');
const { BusinessNetworkDefinition, IdCard } = require('composer-common');
const { BusinessNetworkDefinition, IdCard, NetworkCardStoreManager } = require('composer-common');
const generator = require('../generators/loopback');
const helpers = require('yeoman-test');
const path = require('path');
const rewire = require('rewire');
Expand Down Expand Up @@ -60,17 +61,18 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',

before(async () => {
if (liveNetwork) {
const cardStore = NetworkCardStoreManager.getCardStore({ type: 'composer-wallet-inmemory' });
const blockchainNetworkCard = new IdCard({
userName : 'admin',
enrollmentSecret : 'adminpw'
}, {
'x-type' : 'embedded',
name : 'generatorProfile'
});
const adminConnection = new AdminConnection({ wallet: { type: 'composer-wallet-inmemory' }});
const adminConnection = new AdminConnection({ cardStore });
await adminConnection.importCard('admin@blockchain-network', blockchainNetworkCard);
await adminConnection.connect('admin@blockchain-network');
const businessNetworkArchive = fs.readFileSync(path.resolve(__dirname + '/data/', 'digitalPropertyNetwork.bna'));
const businessNetworkArchive = fs.readFileSync(path.resolve(__dirname + '/data/', 'carAuction.bna'));
const businessNetworkDefinition = await BusinessNetworkDefinition.fromArchive(businessNetworkArchive);
await adminConnection.install(businessNetworkDefinition);
await adminConnection.start(businessNetworkDefinition.getName(), businessNetworkDefinition.getVersion(), {
Expand All @@ -79,27 +81,37 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
enrollmentSecret : 'adminpw'
}]
});
const businessNetworkCard = new IdCard({
userName : 'admin',
enrollmentSecret: 'adminpw',
businessNetwork : 'carauction-network'
}, {
'x-type' : 'embedded',
name : 'generatorProfile'
});
await adminConnection.importCard('admin@carauction-network', businessNetworkCard);
generator.setBusinessNetworkConnectionOptions({ cardStore });
}
});

before(() => {
const prompts = {
liveNetwork,
appName: 'digitalPropertyNetwork',
appDescription: 'A digitalPropertyNetwork application',
appName: 'loopback-carauction',
appDescription: 'A LoopBack application for car auctions',
authorName: 'TestUser',
authorEmail: '[email protected]',
license: 'Apache-2.0',
fileName: (path.join(__dirname, '/data/digitalPropertyNetwork.bna')),
cardName: 'admin@digitalproperty-network'
fileName: (path.join(__dirname, '/data/carAuction.bna')),
cardName: 'admin@carauction-network'
};
if (liveNetwork) {
delete prompts.fileName;
}
return helpers.run(path.resolve(__dirname, '../generators/loopback'))
.inTmpDir((dir) => {
tmpDir = dir;
appDir = path.join(tmpDir, 'digitalPropertyNetwork');
appDir = path.join(tmpDir, 'loopback-carauction');
})
.withOptions({ skipInstall: true })
.withPrompts(prompts)
Expand Down Expand Up @@ -165,14 +177,18 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
return builtInModelFiles.indexOf(fileName) === -1;
});
fileNames.should.deep.equal([
'LandTitle.js',
'LandTitle.json',
'Person.js',
'Person.json',
'RegisterPropertyForSale.js',
'RegisterPropertyForSale.json',
'SalesAgreement.js',
'SalesAgreement.json',
'Auctioneer.js',
'Auctioneer.json',
'CloseBidding.js',
'CloseBidding.json',
'Member.js',
'Member.json',
'Offer.js',
'Offer.json',
'Vehicle.js',
'Vehicle.json',
'VehicleListing.js',
'VehicleListing.json'
]);
files.forEach((file) => {
if (file.endsWith('.js')) {
Expand All @@ -187,7 +203,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
sinon.assert.calledWith(mockComposer.restrictModelMethods, mockModel);
} else {
const modelJSON = require(file);
modelJSON.options.composer.namespace.should.equal('net.biz.digitalPropertyNetwork');
modelJSON.options.composer.namespace.should.equal('org.acme.vehicle.auction');
}
});
});
Expand Down Expand Up @@ -215,7 +231,7 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
const datasources = require(file);
datasources.should.deep.equal({
composer: {
card: 'admin@digitalproperty-network',
card: 'admin@carauction-network',
connector: 'loopback-connector-composer',
name: 'composer',
namespaces: false
Expand Down Expand Up @@ -250,19 +266,27 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
dataSource: 'composer',
public: false
},
LandTitle: {
Auctioneer: {
dataSource: 'composer',
public: true
},
CloseBidding: {
dataSource: 'composer',
public: true
},
Member: {
dataSource: 'composer',
public: true
},
SalesAgreement: {
Offer: {
dataSource: 'composer',
public: true
},
Person: {
Vehicle: {
dataSource: 'composer',
public: true
},
RegisterPropertyForSale: {
VehicleListing: {
dataSource: 'composer',
public: true
}
Expand All @@ -273,9 +297,9 @@ describe('hyperledger-composer:loopback for generating a LoopBack application',
const file = path.join(appDir, 'package.json');
assert.file(file);
const packageJSON = require(file);
packageJSON.name.should.equal('digitalPropertyNetwork');
packageJSON.name.should.equal('loopback-carauction');
packageJSON.version.should.equal('1.0.0');
packageJSON.description.should.equal('A digitalPropertyNetwork application');
packageJSON.description.should.equal('A LoopBack application for car auctions');
packageJSON.license.should.equal('Apache-2.0');
packageJSON.author.should.equal('TestUser <[email protected]>');
packageJSON.engines.should.deep.equal({
Expand Down

0 comments on commit 26ef1b6

Please sign in to comment.