Skip to content

Commit

Permalink
[WIP #165] Add some integration tests to api/delegates. Add chai-sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanever committed Apr 14, 2018
1 parent 34c6777 commit 8586677
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -80,6 +80,7 @@
"chai": "=4.1.2",
"chai-arrays": "=2.0.0",
"chai-as-promised": "^7.1.1",
"chai-sorted": "^0.2.0",
"coveralls": "=2.11.16",
"dpos-offline": "=1.3.5",
"mocha": "=5.0.5",
Expand Down
77 changes: 71 additions & 6 deletions tests/integration/api/delegates.spec.ts
@@ -1,5 +1,12 @@
import initializer from '../common/init';
import { checkEnumParam, checkIntParam, checkPubKey, checkRequiredParam, checkReturnObjKeyVal } from './utils';
import * as supertest from 'supertest';
import * as chai from 'chai';
import * as chaiSorted from 'chai-sorted';
chai.use(chaiSorted);

const {expect} = chai;
const delegates = require('../genesisDelegates.json');

// tslint:disable no-unused-expression max-line-length
describe('api/delegates', () => {
Expand All @@ -20,19 +27,77 @@ describe('api/delegates', () => {
checkIntParam('offset', '/api/delegates', { min: 0 });

checkReturnObjKeyVal('totalCount', 101, '/api/delegates');
it('should return delegates array');
it('should honor orderBy asc param');
it('should honor orderBy desc param');
it('should honor limit param');
it('should honor offset param');

it('should return delegates array', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(Array.isArray(response.body.delegates));
expect(response.body.delegates.map((d) => d.address).sort()).to.be.deep.equal(delegates.map((d) => d.address).sort());
});
});

['approval', 'productivity', 'rank', 'vote', 'username', 'address', 'publicKey'].forEach((sortKey: string) => {
it('should honor orderBy ' + sortKey + ' asc param', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/?orderBy=' + sortKey + ':asc')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(Array.isArray(response.body.delegates)).to.be.true;
expect(response.body.delegates).to.be.ascendingBy(sortKey);
});
});
it('should honor orderBy ' + sortKey + ' desc param', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/?orderBy=' + sortKey + ':desc')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(Array.isArray(response.body.delegates)).to.be.true;
expect(response.body.delegates).to.be.descendingBy(sortKey);
});
});
});
it('should honor limit param', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/?limit=10')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(Array.isArray(response.body.delegates)).to.be.true;
expect(response.body.delegates.length).to.be.equal(10);
});
});

it('should honor offset param', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/?offset=30')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(Array.isArray(response.body.delegates)).to.be.true;
expect(response.body.delegates.length).to.be.equal(71);
});
});
});

describe('/fee', () => {
checkIntParam('height', '/api/delegates/fee', { min: 1 });
checkReturnObjKeyVal('fromHeight', 1, '/api/delegates/fee');
checkReturnObjKeyVal('toHeight', null, '/api/delegates/fee');
checkReturnObjKeyVal('height', 2, '/api/delegates/fee');
it('should return fee value for delegate');
it('should return fee value for delegate', async () => {
return supertest(initializer.appManager.expressApp)
.get('/api/delegates/fee')
.expect(200)
.then((response) => {
expect(response.body.success).is.true;
expect(response.body.fee).to.be.equal(2500000000);
});
});
});

describe('/forging/getForgedByAccount', () => {
Expand Down

0 comments on commit 8586677

Please sign in to comment.