Skip to content

Commit

Permalink
Fix adding invalid model files (hyperledger-archives#1441)
Browse files Browse the repository at this point in the history
Updated to give an error if you try adding an invalid model file
  • Loading branch information
cazfletch authored and samjsmith committed Jul 3, 2017
1 parent 77a25c8 commit ac1abc2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,17 @@ describe('EditorComponent', () => {
{
getNamespace: sinon.stub().returns('model 2'),
getName: sinon.stub().returns('models/model2.cto'),
isSystemModelFile : sinon.stub().returns(false)
isSystemModelFile: sinon.stub().returns(false)
},
{
getNamespace: sinon.stub().returns('model 1'),
getName: sinon.stub().returns('models/model1.cto'),
isSystemModelFile : sinon.stub().returns(false)
isSystemModelFile: sinon.stub().returns(false)
},
{
getNamespace: sinon.stub().returns('system 1'),
getName: sinon.stub().returns('models/system1.cto'),
isSystemModelFile : sinon.stub().returns(true)
isSystemModelFile: sinon.stub().returns(true)
},
]);

Expand Down Expand Up @@ -1194,6 +1194,24 @@ describe('EditorComponent', () => {
mockClientService.businessNetworkChanged$.next.should.not.have.been.called;
mockAlertService.errorStatus$.next.should.not.have.been.called;
}));

it('should open AddFileComponent modal and show error if business network not valid', fakeAsync(() => {

mockAddModel.throws('some error');
mockModal.open = sinon.stub().returns({
componentInstance: {
businessNetwork: {}
},
result: Promise.resolve(mockModelFile)
});

component.openAddFileModal();

tick();

mockAddModel.should.have.been.called;
mockAlertService.errorStatus$.next.should.have.been.called;
}));
});

describe('deploy', () => {
Expand Down
22 changes: 13 additions & 9 deletions packages/composer-playground/src/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,20 @@ export class EditorComponent implements OnInit, OnDestroy {
this.modalService.open(AddFileComponent).result
.then((result) => {
if (result !== 0) {
if (result instanceof ModelFile) {
this.addModelFile(result);
} else if (result instanceof Script) {
this.addScriptFile(result);
} else if (result instanceof AclFile) {
this.addRuleFile(result);
} else {
this.addReadme(result);
try {
if (result instanceof ModelFile) {
this.addModelFile(result);
} else if (result instanceof Script) {
this.addScriptFile(result);
} else if (result instanceof AclFile) {
this.addRuleFile(result);
} else {
this.addReadme(result);
}
this.clientService.businessNetworkChanged$.next(true);
} catch (error) {
this.alertService.errorStatus$.next(error);
}
this.clientService.businessNetworkChanged$.next(true);
}
}, (reason) => {
if (reason && reason !== 1) {
Expand Down

0 comments on commit ac1abc2

Please sign in to comment.