Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: include last delegate page when fetching (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Mar 14, 2020
1 parent 3772fe4 commit 6e0815e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
47 changes: 36 additions & 11 deletions __tests__/unit/store/modules/delegate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,44 @@ describe('delegate store module', () => {
expect(store.getters['delegate/byPublicKey']()).toBe(false)
})

it('should fetch delegates from api', async () => {
nock('http://127.0.0.1')
.get('/api/v2/delegates')
.query({ page: 1, limit: 100, orderBy: 'rank:asc' })
.reply(200, {
data: delegates,
meta: {
totalCount: 2
}
describe('dispatch', () => {
describe('load', () => {
it('should fetch delegates from api', async () => {
nock('http://127.0.0.1')
.get('/api/v2/delegates')
.query({ page: 1, limit: 100, orderBy: 'rank:asc' })
.reply(200, {
data: delegates,
meta: {
totalCount: 2
}
})

await store.dispatch('delegate/load')

expect(Object.values(store.getters['delegate/all'][profile1.networkId])).toEqual(delegates)
})

await store.dispatch('delegate/load')
it('should load all pages', async () => {
const pageCount = 10

expect(Object.values(store.getters['delegate/all'][profile1.networkId])).toEqual(delegates)
for (let page = 1; page <= pageCount; page++) {
nock('http://127.0.0.1')
.get('/api/v2/delegates')
.query({ page, limit: 100, orderBy: 'rank:asc' })
.reply(200, {
data: delegates.map(delegate => ({ ...delegate, address: `${delegate.address}-${page}` })),
meta: {
pageCount: 10,
totalCount: (delegates.length * 10)
}
})
}

await store.dispatch('delegate/load')

expect(Object.values(store.getters['delegate/all'][profile1.networkId]).length).toEqual(delegates.length * 10)
})
})
})
})
2 changes: 1 addition & 1 deletion src/renderer/store/modules/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
})

const requests = []
for (let page = 2; page < delegatePage1.meta.pageCount; page++) {
for (let page = 2; page <= delegatePage1.meta.pageCount; page++) {
requests.push(this._vm.$client.fetchDelegates({
page,
limit: 100
Expand Down

0 comments on commit 6e0815e

Please sign in to comment.