Skip to content

Commit

Permalink
Fix hasTransactions flag in playground (hyperledger-archives#3866)
Browse files Browse the repository at this point in the history
hasTransactions should be false if there are no user modeled
transactions however it had not been updated to ignore system
transactions

Closes #3796

Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti authored Apr 18, 2018
1 parent 545b32c commit c857dd0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
41 changes: 40 additions & 1 deletion packages/composer-playground/src/app/test/test.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('TestComponent', () => {
component.hasTransactions.should.be.true;
}));

it('should load all the registries and hasTransactions should be false', fakeAsync(() => {
it('should load all the registries and hasTransactions should be false when there are no transactions', fakeAsync(() => {
mockClientService.ensureConnected.returns(Promise.resolve());

mockBusinessNetworkConnection.getAllAssetRegistries.returns(Promise.resolve([{id: 'asset.fred'}, {id: 'asset.bob'}]));
Expand Down Expand Up @@ -198,6 +198,45 @@ describe('TestComponent', () => {
component.hasTransactions.should.be.false;
}));

it('should load all the registries and hasTransactions should be false when there are only system transactions', fakeAsync(() => {
mockClientService.ensureConnected.returns(Promise.resolve());

mockBusinessNetworkConnection.getAllAssetRegistries.returns(Promise.resolve([{id: 'asset.fred'}, {id: 'asset.bob'}]));
mockBusinessNetworkConnection.getAllParticipantRegistries.returns(Promise.resolve([{id: 'participant.fred'}, {id: 'participant.bob'}]));
mockBusinessNetworkConnection.getHistorian.returns(Promise.resolve('historianRegistry'));
mockClientService.getBusinessNetworkConnection.returns(mockBusinessNetworkConnection);
mockTransaction.isSystemType.returns(true);

component.ngOnInit();

tick();

mockClientService.getBusinessNetworkConnection.should.have.been.called;
mockBusinessNetworkConnection.getAllAssetRegistries.should.have.been.called;

component['registries']['assets'].length.should.equal(2);
component['registries']['assets'][0].should.deep.equal({id: 'asset.bob', displayName: 'bob'});
component['registries']['assets'][1].should.deep.equal({id: 'asset.fred', displayName: 'fred'});

mockBusinessNetworkConnection.getAllParticipantRegistries.should.have.been.called;

component['registries']['participants'].length.should.equal(2);

component['registries']['participants'][0].should.deep.equal({id: 'participant.bob', displayName: 'bob'});
component['registries']['participants'][1].should.deep.equal({id: 'participant.fred', displayName: 'fred'});

mockBusinessNetworkConnection.getHistorian.should.have.been.called;

component['registries']['historian'].should.equal('historianRegistry');

component['chosenRegistry'].should.deep.equal({id: 'participant.bob', displayName: 'bob'});

mockClientService.getBusinessNetwork.should.have.been.called;
mockBusinessNetwork.getIntrospector.should.have.been.called;
mockIntrospector.getClassDeclarations.should.have.been.called;
component.hasTransactions.should.be.false;
}));

it('should set chosen registry to first asset one if no participant registries', fakeAsync(() => {
mockClientService.ensureConnected.returns(Promise.resolve());

Expand Down
4 changes: 2 additions & 2 deletions packages/composer-playground/src/app/test/test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class TestComponent implements OnInit, OnDestroy {
let introspector = this.clientService.getBusinessNetwork().getIntrospector();
let modelClassDeclarations = introspector.getClassDeclarations();
modelClassDeclarations.forEach((modelClassDeclaration) => {
// Generate list of all known (non-abstract) transaction types
if (!modelClassDeclaration.isAbstract() && modelClassDeclaration instanceof TransactionDeclaration) {
// Generate list of all known (non-abstract/non-system) transaction types
if (!modelClassDeclaration.isAbstract() && !modelClassDeclaration.isSystemType() && modelClassDeclaration instanceof TransactionDeclaration) {
this.hasTransactions = true;
}
});
Expand Down

0 comments on commit c857dd0

Please sign in to comment.