Skip to content

Commit

Permalink
increase test coverage (hyperledger-archives#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
nklincoln authored Sep 8, 2017
1 parent b1fdf59 commit cbb3610
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,15 @@ describe('AdminService', () => {
adminConnectionMock.disconnect.should.have.been.called;
})));
});

describe('generateDefaultBusinessNetwork', () => {
it('should generate a new business definition', inject([AdminService], (service: AdminService) => {
sinon.restore(businessNetworkDefMock);

let defaultBusNet: BusinessNetworkDefinition = service.generateDefaultBusinessNetwork('name', 'desc');
defaultBusNet.getDescription().should.be.equal('desc');
defaultBusNet.getName().should.be.equal('name');
defaultBusNet.getVersion().should.be.equal('0.0.1');
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('ClientService', () => {
sandbox.restore();
});

describe('createBusinessNetwork', () => {
it('should pass through and call createNewBusinessDefinition from common', inject([ClientService], (service: ClientService) => {
let name = 'myname';
let nameversion = '[email protected]';
let desc = 'my description';

let busNetDef = service.createBusinessNetwork(nameversion, desc, null, null);
busNetDef.getName().should.equal(name);
busNetDef.getDescription().should.equal(desc);
busNetDef.getVersion().should.equal('0.0.1');
}));
});

describe('getBusinessNetworkConnection', () => {
it('should get business network connection if set', inject([ClientService], (service: ClientService) => {
service['businessNetworkConnection'] = businessNetworkConMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('ConfigService', () => {
describe('isWebOnly', () => {
it('should throw if not initialized', fakeAsync(inject([ConfigService], (service: ConfigService) => {
(() => {
service.getConfig();
service.isWebOnly();
}).should.throw(/config has not been loaded/);
})));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('SampleBusinessNetworkService', () => {
let clientMock;
let aclFileMock;
let alertMock;
let businessNetworkMock = sinon.createStubInstance(BusinessNetworkDefinition);
let businessNetworkMock;
let sandbox;
let identityCardMock;

Expand All @@ -40,6 +40,7 @@ describe('SampleBusinessNetworkService', () => {
clientMock = sinon.createStubInstance(ClientService);
aclFileMock = sinon.createStubInstance(AclFile);
alertMock = sinon.createStubInstance(AlertService);
businessNetworkMock = sinon.createStubInstance(BusinessNetworkDefinition);

alertMock.busyStatus$ = {next: sinon.stub()};

Expand All @@ -59,6 +60,21 @@ describe('SampleBusinessNetworkService', () => {
sandbox.restore();
});

describe('createNewBusinessDefinition', () => {
it('should pass through and call createNewBusinessDefinition from common', inject([SampleBusinessNetworkService], (service: SampleBusinessNetworkService) => {
sinon.restore(businessNetworkMock);

let name = 'myname';
let nameversion = '[email protected]';
let desc = 'my description';

let busNetDef = service.createNewBusinessDefinition(nameversion, desc, null, null);
busNetDef.getName().should.equal(name);
busNetDef.getDescription().should.equal(desc);
busNetDef.getVersion().should.equal('0.0.1');
}));
});

describe('getSampleList', () => {
it('should get the list of sample networks', fakeAsync(inject([SampleBusinessNetworkService, XHRBackend], (service: SampleBusinessNetworkService, mockBackend) => {
mockBackend.connections.subscribe((connection) => {
Expand Down Expand Up @@ -269,6 +285,9 @@ describe('SampleBusinessNetworkService', () => {
adminMock.connect.returns(Promise.resolve());
adminMock.update.returns(Promise.reject('some error'));

let metaData = {getPackageJson: sinon.stub().returns({})};
businessNetworkMock.getMetadata.returns(metaData);

service.updateBusinessNetwork(businessNetworkMock).then(() => {
throw('should not get here');
})
Expand Down

0 comments on commit cbb3610

Please sign in to comment.