Skip to content

Commit

Permalink
Added some improvements to 'helpers/bus' tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jarenal committed Feb 7, 2018
1 parent 684fff3 commit c343b9a
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions tests/unit/helpers/bus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('helpers/bus', () => {
let sandbox: SinonSandbox;
let instance: Bus;
let stub: any;
let stub2: any;

beforeEach(() => {
instance = new Bus();
Expand All @@ -27,91 +28,103 @@ describe('helpers/bus', () => {
});

describe('receiveBlock', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onReceiveBlock: stub}];
instance.message('receiveBlock', {the: 'block'} as any);
await instance.message('receiveBlock', {the: 'block'} as any);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.be.deep.eq({the: 'block'});
});
});

describe('finishRound', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onFinishRound: stub}];
instance.message('finishRound', 10);
await instance.message('finishRound', 10);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.equal(10);
});
});

describe('transactionsSaved', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onTransactionsSaved: stub}];
instance.message('transactionsSaved', [1, 2, 3] as any);
await instance.message('transactionsSaved', [1, 2, 3] as any);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.be.equalTo([1, 2, 3]);
});
});

describe('blockchainReady', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onBlockchainReady: stub}];
instance.message('blockchainReady');
await instance.message('blockchainReady');
expect(stub.calledOnce).is.true;
});
});

describe('syncStarted', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onSyncStarted: stub}];
instance.message('syncStarted');
await instance.message('syncStarted');
expect(stub.calledOnce).is.true;
});
});

describe('syncFinished', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onSyncFinished: stub}];
instance.message('syncFinished');
await instance.message('syncFinished');
expect(stub.calledOnce).is.true;
});
});

describe('peersReady', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onPeersReady: stub}];
instance.message('peersReady');
await instance.message('peersReady');
expect(stub.calledOnce).is.true;
});
});

describe('newBlock', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onNewBlock: stub}];
instance.message('newBlock', {foo: 'bar'} as any, true);
await instance.message('newBlock', {foo: 'bar'} as any, true);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.deep.equal({foo: 'bar'});
expect(stub.args[0][1]).to.be.true;
});
});

describe('signature', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onSignature: stub}];
instance.message('signature', {transaction: 'foo', signature: 123}, true);
await instance.message('signature', {transaction: 'foo', signature: 123}, true);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.deep.equal({transaction: 'foo', signature: 123});
expect(stub.args[0][1]).to.be.true;
});
});

describe('unconfirmedTransaction', () => {
it('success', () => {
it('success', async () => {
instance.modules = [{onUnconfirmedTransaction: stub}];
instance.message('unconfirmedTransaction', 'abc', true);
await instance.message('unconfirmedTransaction', 'abc', true);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.equal('abc');
expect(stub.args[0][1]).to.be.true;
});
});

describe('Testing multiple listeners', () => {
it('success', async () => {
stub2 = sandbox.stub().resolves();
instance.modules = [{onReceiveBlock: stub}, {onReceiveBlock: stub2}];
await instance.message('receiveBlock', {the: 'block'} as any);
expect(stub.calledOnce).is.true;
expect(stub.args[0][0]).to.be.deep.eq({the: 'block'});
expect(stub2.calledOnce).is.true;
expect(stub2.args[0][0]).to.be.deep.eq({the: 'block'});
});
});
});

0 comments on commit c343b9a

Please sign in to comment.