Skip to content

Commit

Permalink
Fixes #169
Browse files Browse the repository at this point in the history
  • Loading branch information
jarenal committed Apr 18, 2018
1 parent ab495bd commit 42b12f4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions tests/unit/apis/loaderAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import { SinonSandbox } from 'sinon';
import * as sinon from 'sinon';
import { LoaderAPI } from '../../../src/apis/loaderAPI';
import { LoaderAPI } from '../../../src/apis';
import { Symbols } from '../../../src/ioc/symbols';
import {
AppStateStub,
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('apis/blocksAPI', () => {

describe('getStatus', () => {

it('success', () => {
it('should return an object with the property \'loaded\' equal to true', () => {
const ret = instance.getStatus();

expect(ret).to.be.deep.equal({ loaded: true });
Expand All @@ -62,7 +62,7 @@ describe('apis/blocksAPI', () => {

describe('getStatusSync', () => {

it('success', () => {
it('should return an object with the properties: broadhash, consensus, height and syncing', () => {
appState.enqueueResponse('get', 'consensus');

const ret = instance.getStatusSync();
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/apis/multisignatureAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import * as sinon from 'sinon';
import { SinonSandbox } from 'sinon';
import { MultisignatureAPI } from '../../../src/apis/multisignatureAPI';
import { MultisignatureAPI } from '../../../src/apis';
import { Symbols } from '../../../src/ioc/symbols';
import {
AccountsModuleStub,
Expand Down Expand Up @@ -69,13 +69,13 @@ describe('apis/multisignatureAPI', () => {
account3 = { id: 3, address: 'ccc', publicKey: 'c3c3c3', balance: 300 };
account4 = { id: 4, address: 'ddd', publicKey: 'c4c4c4', balance: 400 };
account5 = {
u_multimin: 10,
u_multilifetime: 20,
u_multimin: 10,
u_multisignatures: ['a', 'b', 'c'],
};
account6 = {
multimin: 100,
multilifetime: 200,
multimin: 100,
u_multisignatures: undefined,
};

Expand Down Expand Up @@ -120,7 +120,7 @@ describe('apis/multisignatureAPI', () => {
});

describe('getAccounts()', () => {
it('success', async () => {
it('should return an array of accounts', async () => {
result = await instance.getAccounts({ publicKey: '123' });
const accounts = [];
accounts.push({ ...account1, ...{ multisigaccounts: [account3] } });
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('apis/multisignatureAPI', () => {
});

describe('getPending()', () => {
it('success', async () => {
it('should return an object with pending transactions', async () => {
result = await instance.getPending({ publicKey: 100 });
expect(result).to.deep.equal({
transactions: [
Expand All @@ -182,13 +182,13 @@ describe('apis/multisignatureAPI', () => {
});

describe('sign()', () => {
it('Throws deprecated', async () => {
it('should throw deprecated', async () => {
await expect(instance.sign()).to.be.rejectedWith('Method is deprecated');
});
});

describe('addMultisignature()', () => {
it('Throws deprecated', async () => {
it('should throw deprecated', async () => {
await expect(instance.addMultisignature()).to.be.rejectedWith(
'Method is deprecated'
);
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/apis/peersAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import * as sinon from 'sinon';
import { SinonSandbox } from 'sinon';
import { PeersAPI } from '../../../src/apis/peersAPI';
import { PeersAPI } from '../../../src/apis';
import { Symbols } from '../../../src/ioc/symbols';
import { PeerState } from '../../../src/logic/';
import { PeersModuleStub, SystemModuleStub } from '../../stubs';
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('apis/peersAPI', () => {
});
});

it('success', async () => {
it('should return an object with a peers property', async () => {
result = await instance.getPeers({ a: 1, b: 2 });
expect(result).to.deep.equal({ peers: { hello: 'world' } });
expect(peersModuleStub.stubs.getByFilter.calledOnce).to.be.true;
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('apis/peersAPI', () => {
});
});

it('success', async () => {
it('should return an object with a peer property', async () => {
peersModuleStub.stubs.getByFilter.returns([{ a: 1 }, { b: 2 }]);
result = await instance.getPeer({ ip: '8.8.8.8', port: 1234 });
expect(result).to.deep.equal({ peer: { a: 1 } });
Expand All @@ -114,7 +114,7 @@ describe('apis/peersAPI', () => {
);
});

it('success', async () => {
it('should return an object with the properties: banned, connected and disconnected', async () => {
peersModuleStub.stubs.getByFilter.onCall(0).returns([{ a: 1 }]);
peersModuleStub.stubs.getByFilter.onCall(1).returns([{ a: 1 }, { b: 2 }]);
peersModuleStub.stubs.getByFilter
Expand All @@ -139,7 +139,7 @@ describe('apis/peersAPI', () => {
});

describe('version()', () => {
it('success', async () => {
it('should return an object with the properties: build, minVersion and version', async () => {
result = await instance.version();
expect(result).to.deep.equal({
build: '1.2.3',
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/apis/signatureAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import * as sinon from 'sinon';
import { SinonSandbox } from 'sinon';
import { SignaturesAPI } from '../../../src/apis/signatureAPI';
import { SignaturesAPI } from '../../../src/apis';
import { Symbols } from '../../../src/ioc/symbols';
import { SystemModuleStub } from '../../stubs';
import { createContainer } from '../../utils/containerCreator';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('apis/signatureAPI', () => {
});

describe('fees()', () => {
it('success', async () => {
it('should return an object with the properties: fee, fromHeight, height and toHeight', async () => {
result = await instance.fees({ height: 123 });
expect(result).to.deep.equal({
fee: 10,
Expand All @@ -59,7 +59,7 @@ describe('apis/signatureAPI', () => {
});

describe('addSignature()', () => {
it('Throws deprecated', async () => {
it('should throw deprecated', async () => {
await expect(instance.addSignature()).to.be.rejectedWith(
'Method is deprecated'
);
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/apis/transactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import * as sinon from 'sinon';
import { SinonSandbox } from 'sinon';
import { TransactionsAPI } from '../../../src/apis/transactions';
import { TransactionsAPI } from '../../../src/apis';
import * as helpers from '../../../src/helpers';
import { TransactionType } from '../../../src/helpers';
import { Symbols } from '../../../src/ioc/symbols';
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('apis/transactionsAPI', () => {
});

describe('getTransactions()', () => {
it('success', async () => {
it('should return an object with the properties: transactions and count', async () => {
const body = {
blockId: '100',
fromHeight: '123',
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('apis/transactionsAPI', () => {
});

describe('getCount()', () => {
it('success', async () => {
it('should return an object with the properties: confirmed, multisignature, queued and unconfirmed', async () => {
result = await instance.getCount();
expect(result).to.deep.equal({
confirmed: 1,
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('apis/transactionsAPI', () => {
transactionsModuleStub.stubs.getByID.returns(
Promise.resolve({ id: 456, type: TransactionType.DELEGATE })
);
result = await instance.getTX('123');
result = await instance.getTX({id: '123'});
expect(result).to.deep.equal({
transaction: { id: 456, type: TransactionType.DELEGATE },
});
Expand Down Expand Up @@ -246,12 +246,12 @@ describe('apis/transactionsAPI', () => {
});

describe('getMultiSig()', () => {
it('success', async () => {
it('should return an object with a transaction', async () => {
result = await instance.getMultiSig('123');
expect(result).to.deep.equal({ transaction: { id: '123' } });
});

it('fail', async () => {
it('should to be reject with the message \'Transaction not found\'', async () => {
transactionsModuleStub.stubs.getMultisignatureTransaction.returns(
undefined
);
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('apis/transactionsAPI', () => {
transactions: [
{ id: 100, senderPublicKey: 'aaa', recipientId: 'bbb' },
{ id: 200, senderPublicKey: 'aaa', recipientId: 'bbb' },
{ id: 400, senderPublicKey: 'aaa', recipientId: 'ddd' }
{ id: 400, senderPublicKey: 'aaa', recipientId: 'ddd' },
],
});
expect(result.transactions).to.be.ofSize(3);
Expand All @@ -380,7 +380,7 @@ describe('apis/transactionsAPI', () => {
count: 5,
transactions: [
{ id: 400, senderPublicKey: 'aaa', recipientId: 'ddd' },
{ id: 500, senderPublicKey: 'ccc', recipientId: 'ddd' }
{ id: 500, senderPublicKey: 'ccc', recipientId: 'ddd' },
],
});
expect(result.transactions).to.be.ofSize(2);
Expand All @@ -395,28 +395,28 @@ describe('apis/transactionsAPI', () => {
{ id: 200, senderPublicKey: 'aaa', recipientId: 'bbb' },
{ id: 300, senderPublicKey: 'ccc', recipientId: 'bbb' },
{ id: 400, senderPublicKey: 'aaa', recipientId: 'ddd' },
{ id: 500, senderPublicKey: 'ccc', recipientId: 'ddd' }
{ id: 500, senderPublicKey: 'ccc', recipientId: 'ddd' },
],
});
expect(result.transactions).to.be.ofSize(5);
});
});

describe('getUnconfirmedTx()', () => {
it('success', async () => {
it('should return an object with a transaction', async () => {
result = await instance.getUnconfirmedTx('123');
expect(result).to.deep.equal({ transaction: { id: '123' } });
});

it('fail', async () => {
it('should to be reject with a message \'Transaction not found\'', async () => {
transactionsModuleStub.stubs.getUnconfirmedTransaction.returns(undefined);
await expect(instance.getUnconfirmedTx('123')).to.be.rejectedWith(
'Transaction not found'
);
});
});
describe('put', () => {
it('should throw error', async () => {
it('should throw deprecated', async () => {
await expect(instance.put()).to.be.rejectedWith('Method is deprecated');
});
});
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/apis/transportAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import { Container } from 'inversify';
import * as sinon from 'sinon';
import { SinonSandbox } from 'sinon';
import { TransportAPI } from '../../../src/apis/transportAPI';
import { TransportAPI } from '../../../src/apis';
import { Symbols } from '../../../src/ioc/symbols';
import {
BlocksModuleStub,
Expand Down Expand Up @@ -106,28 +106,28 @@ describe('apis/transportAPI', () => {
});

describe('height()', () => {
it('success', () => {
it('should return an object with the property height', () => {
result = instance.height();
expect(result).to.deep.equal({ height: 101 });
});
});

describe('ping()', () => {
it('success', () => {
it('should return an empty object', () => {
result = instance.ping();
expect(result).to.deep.equal({});
});
});

describe('list()', () => {
it('success', async () => {
it('should return an object with the property peers', async () => {
result = await instance.list();
expect(result).to.deep.equal({ peers: ['a', 'b', 'c'] });
});
});

describe('signatures()', () => {
it('success', () => {
it('should return an object with the property signatures', () => {
result = instance.signatures();
expect(result).to.deep.equal({
signatures: [
Expand All @@ -150,7 +150,7 @@ describe('apis/transportAPI', () => {
});

describe('transactions()', () => {
it('success', () => {
it('should return an object with the property transactions', () => {
result = instance.transactions();
expect(result).to.deep.equal({
transactions: [{ id: 10 }, { id: 11 }, { id: 12 }],
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('apis/transportAPI', () => {
expect(peersModuleStub.stubs.remove.args[0][1]).to.equal(1234);
});

it('success #1', async () => {
it('should return an object with the property \'common\' equal to true', async () => {
result = await instance.getBlocksCommon('1,2,3', {} as any);
expect(result).to.deep.equal({ common: true });
expect(dbStub.stubs.query.calledOnce).to.be.true;
Expand All @@ -257,7 +257,7 @@ describe('apis/transportAPI', () => {
expect(dbStub.stubs.query.args[0][1]).to.deep.equal(['1', '2', '3']);
});

it('success #2', async () => {
it('should return an object with the property \'common\' equal to null', async () => {
dbStub.stubs.query.returns([]);
result = await instance.getBlocksCommon('1,2,3', {} as any);
expect(result).to.deep.equal({ common: null });
Expand All @@ -271,7 +271,7 @@ describe('apis/transportAPI', () => {
});

describe('postBlock()', () => {
it('success', async () => {
it('should return an object with the property blockId', async () => {
result = await instance.postBlock(
{ foo: 'bar' } as any,
{ ip: '8.8.8.8', headers: { port: '1234' } } as any
Expand All @@ -286,7 +286,7 @@ describe('apis/transportAPI', () => {
expect(busStub.stubs.message.args[0][1]).to.deep.equal({ id: 123 });
});

it('error', async () => {
it('should be rejected', async () => {
blockLogicStub.stubs.objectNormalize.throws(
new Error('objectNormalizeError')
);
Expand All @@ -307,7 +307,7 @@ describe('apis/transportAPI', () => {
});

describe('getBlocks()', () => {
it('success', async () => {
it('should return an object with the property blocks', async () => {
result = await instance.getBlocks('123');
expect(result).to.deep.equal({
blocks: [{ id: 1 }, { id: 2 }, { id: 3 }],
Expand Down

0 comments on commit 42b12f4

Please sign in to comment.