Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apps/whale-api): api error when getting all data using OCG listing endpoint but response is empty #2016

Merged
merged 5 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/whale-api/src/module.api/_core/api.paged.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ApiPagedResponse<T> extends ApiRawResponse {
* @param {(item: T) => string} nextProvider to get next token when (limit === data array slice)
*/
static of<T> (data: T[], limit: number, nextProvider: (item: T) => string): ApiPagedResponse<T> {
if (data.length === limit) {
if (data.length === limit && data.length > 0 && limit > 0) {
const next = nextProvider(data[limit - 1])
return this.next(data, next)
}
Expand Down
9 changes: 7 additions & 2 deletions apps/whale-api/src/module.api/governance.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ describe('governance - listProposals and getProposal', () => {
size: 0
})
expect(result.data.length).toStrictEqual(2)
const emptyResult = await controller.listProposals(ListProposalsStatus.REJECTED, undefined, undefined, undefined, {
size: 0
})
expect(emptyResult.data.length).toStrictEqual(0)
})

it('should listProposals with all record when all flag is true', async () => {
Expand All @@ -174,8 +178,7 @@ describe('governance - listProposals and getProposal', () => {
expect(resultPage2.data.length).toStrictEqual(1)
})

// TODO: remove skip when blockchain fixes issue where start is ignored when non-all status is not passed
it.skip('should listProposals with type and pagination', async () => {
it('should listProposals with type and pagination', async () => {
const resultPage1 = await controller.listProposals(undefined, ListProposalsType.CFP, undefined, undefined, {
size: 1
})
Expand Down Expand Up @@ -359,6 +362,8 @@ describe('governance - listProposalVotes', () => {
it('should listProposalVotes with all records when all flag is true', async () => {
const result = await controller.listProposalVotes(cfpProposalId, undefined, undefined, true)
expect(result.data.length).toStrictEqual(3)
const emptyResult = await controller.listProposalVotes(vocProposalId, undefined, undefined, true)
expect(emptyResult.data.length).toStrictEqual(0)
})

it('should listProposalVotes with all masternodes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ describe('Governance', () => {
expect(proposals.length).toStrictEqual(2)
})

// TODO: remove `skip` after blockchain fixes bug where `start` is not considered when non-all status is not passed
it.skip('should listGovProposals with start, including_start and limit', async () => {
it('should listGovProposals with start, including_start and limit', async () => {
const allProposals = await testing.rpc.governance.listGovProposals()
const proposalsPage1 = await testing.rpc.governance.listGovProposals({
pagination: {
Expand All @@ -270,8 +269,8 @@ describe('Governance', () => {
limit: 2
}
})
expect(proposalsPage1.length).toStrictEqual(allProposals.slice(0, 2))
expect(proposalsPage2.length).toStrictEqual(allProposals.slice(2, 4))
expect(proposalsPage1).toStrictEqual(allProposals.slice(0, 2))
expect(proposalsPage2).toStrictEqual(allProposals.slice(2, 4))
})

it('should listGovProposals with status, start, including_start and limit', async () => {
Expand Down Expand Up @@ -320,10 +319,9 @@ describe('Governance', () => {
expect(proposalsPage2).toStrictEqual(allVotingProposals.slice(-1))
})

// TODO: remove `skip` after blockchain fixes bug where `start` is not considered when cycle is passed
it.skip('should listGovProposals with status, type, cycle, start, including_start and limit', async () => {
it('should listGovProposals with status, type, cycle, start, including_start and limit', async () => {
const allVotingProposals = await testing.rpc.governance.listGovProposals().then(
proposals => proposals.filter(proposal => proposal.status === ProposalStatus.VOTING)
proposals => proposals.filter(proposal => proposal.status === ProposalStatus.VOTING && proposal.type === ProposalType.VOTE_OF_CONFIDENCE)
)
const proposalsPage1 = await testing.rpc.governance.listGovProposals({
status: ListProposalsStatus.VOTING,
Expand All @@ -340,7 +338,7 @@ describe('Governance', () => {
type: ListProposalsType.VOC,
cycle: 2,
pagination: {
start: proposalsPage1[1].proposalId,
start: allVotingProposals[2].proposalId,
including_start: true,
limit: 2
}
Expand Down