From 92e5ff20ef321d05c1850712663206460ce9d640 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 17 Jan 2020 12:49:24 +0100 Subject: [PATCH 1/3] Add support to sort delegates by voteWeight for swagger api --- framework/src/modules/http_api/schema/swagger.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/src/modules/http_api/schema/swagger.yml b/framework/src/modules/http_api/schema/swagger.yml index 84aadcec340..995c2ec4fa6 100755 --- a/framework/src/modules/http_api/schema/swagger.yml +++ b/framework/src/modules/http_api/schema/swagger.yml @@ -583,6 +583,8 @@ paths: - missedBlocks:desc - producedBlocks:asc - producedBlocks:desc + - voteWeight:asc + - voteWeight:desc default: username:asc responses: 200: From afec66404d747ef0cd52ad71b6cb2a8a965ed0cf Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 17 Jan 2020 12:49:49 +0100 Subject: [PATCH 2/3] Add a functional test for sorting of voteWeight on http api --- .../mocha/functional/http/get/delegates.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/framework/test/mocha/functional/http/get/delegates.js b/framework/test/mocha/functional/http/get/delegates.js index e60bb2b5e9d..2fe9a1d6a41 100644 --- a/framework/test/mocha/functional/http/get/delegates.js +++ b/framework/test/mocha/functional/http/get/delegates.js @@ -515,6 +515,28 @@ describe('GET /delegates', () => { }); }); + it('using sort="voteWeight:asc" should sort results in ascending order', async () => { + return delegatesEndpoint + .makeRequest({ sort: 'voteWeight:asc' }, 200) + .then(res => { + expect(_.map(res.data, 'voteWeight').sort()).to.eql( + _.map(res.data, 'voteWeight'), + ); + }); + }); + + it('using sort="voteWeight:desc" should sort results in descending order', async () => { + return delegatesEndpoint + .makeRequest({ sort: 'voteWeight:desc' }, 200) + .then(res => { + expect( + _.map(res.data, 'voteWeight') + .sort() + .reverse(), + ).to.eql(_.map(res.data, 'voteWeight')); + }); + }); + it('using sort with any of sort fields should not place NULLs first', async () => { const delegatesSortFields = [ 'username', From cd40fd03f31c724f134e4666871636af9dd9a329 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 17 Jan 2020 13:06:47 +0100 Subject: [PATCH 3/3] Change default sort value for delegates to voteWeight:desc --- elements/lisk-api-client/src/resources/delegates.ts | 4 ++-- framework/src/modules/http_api/schema/swagger.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/elements/lisk-api-client/src/resources/delegates.ts b/elements/lisk-api-client/src/resources/delegates.ts index f894d276319..b9a951ac9d6 100644 --- a/elements/lisk-api-client/src/resources/delegates.ts +++ b/elements/lisk-api-client/src/resources/delegates.ts @@ -31,7 +31,7 @@ export class DelegatesResource extends APIResource { this.get = apiMethod({ defaultData: { - sort: 'username:asc', + sort: 'voteWeight:desc', }, method: GET, }).bind(this); @@ -39,7 +39,7 @@ export class DelegatesResource extends APIResource { this.getStandby = apiMethod({ defaultData: { offset: 101, - sort: 'username:asc', + sort: 'voteWeight:desc', }, method: GET, }).bind(this); diff --git a/framework/src/modules/http_api/schema/swagger.yml b/framework/src/modules/http_api/schema/swagger.yml index 995c2ec4fa6..7f1a37dea33 100755 --- a/framework/src/modules/http_api/schema/swagger.yml +++ b/framework/src/modules/http_api/schema/swagger.yml @@ -585,7 +585,7 @@ paths: - producedBlocks:desc - voteWeight:asc - voteWeight:desc - default: username:asc + default: voteWeight:desc responses: 200: description: Search results matching criteria