-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: top voters sort in back (#1246)
* fix: sort top voters in the back * chore: add test for no votes case
- Loading branch information
Showing
3 changed files
with
2,305 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { def, get } from 'bdd-lazy-var/getter' | ||
|
||
import { SnapshotService } from '../../services/SnapshotService' | ||
import Time from '../../utils/date/Time' | ||
import { getPreviousMonthStartAndEnd } from '../../utils/date/getPreviousMonthStartAndEnd' | ||
import { SNAPSHOT_VOTES_AUGUST_2023 } from '../../utils/votes/utils.testData' | ||
|
||
import { VoteService } from './vote' | ||
|
||
import clearAllMocks = jest.clearAllMocks | ||
|
||
describe('getTopVoters', () => { | ||
const firstOfAugust = Time.utc('2023-08-1T00:00:000Z').toDate() | ||
const { start, end } = getPreviousMonthStartAndEnd(firstOfAugust) | ||
|
||
beforeAll(() => { | ||
jest.spyOn(SnapshotService, 'getAllVotesBetweenDates').mockResolvedValue(SNAPSHOT_VOTES_AUGUST_2023) | ||
}) | ||
|
||
describe('when fetching the top 3', () => { | ||
def('topVoters', async () => await VoteService.getTopVoters(start, end, 3)) | ||
|
||
it('should return the top 3 voters sorted by votes in descending order', async () => { | ||
expect(await get.topVoters).toEqual([ | ||
{ | ||
address: '0xa2f8cd45cd7ea14bce6e87f177cf9df928a089a5', | ||
votes: 79, | ||
}, | ||
{ | ||
address: '0x2684a202a374d87bb321a744482b89bf6deaf8bd', | ||
votes: 75, | ||
}, | ||
{ | ||
address: '0x8218a2445679e38f358e42f88fe2125c98440d59', | ||
votes: 73, | ||
}, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('when called with the default params', () => { | ||
def('topVoters', async () => await VoteService.getTopVoters(start, end)) | ||
|
||
it('should return the top 5 voters sorted by votes in descending order', async () => { | ||
expect(await get.topVoters).toEqual([ | ||
{ | ||
address: '0xa2f8cd45cd7ea14bce6e87f177cf9df928a089a5', | ||
votes: 79, | ||
}, | ||
{ | ||
address: '0x2684a202a374d87bb321a744482b89bf6deaf8bd', | ||
votes: 75, | ||
}, | ||
{ | ||
address: '0x8218a2445679e38f358e42f88fe2125c98440d59', | ||
votes: 73, | ||
}, | ||
{ | ||
address: '0xa77294828d42b538890fa6e97adffe9305536171', | ||
votes: 53, | ||
}, | ||
{ | ||
address: '0x4534c46ea854c9a302d3dc95b2d3253ae6a28abc', | ||
votes: 21, | ||
}, | ||
]) | ||
}) | ||
|
||
describe('when there are no votes on the selected time period', () => { | ||
beforeEach(() => { | ||
clearAllMocks() | ||
jest.spyOn(SnapshotService, 'getAllVotesBetweenDates').mockResolvedValue([]) | ||
}) | ||
|
||
it('should return an empty array', async () => { | ||
expect(await get.topVoters).toEqual([]) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.