-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split up and test a couple more functions
- Loading branch information
1 parent
ecd6041
commit d7874b5
Showing
9 changed files
with
79 additions
and
23 deletions.
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
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,16 @@ | ||
import { StreamSchedule } from '../types/stream.js'; | ||
import { getScheduleStartAndEndTimes } from './schedule.js'; | ||
|
||
export const getStreamsProgress = ( | ||
streamsSchedule: StreamSchedule[], | ||
): number[] => { | ||
const streamsProgress = streamsSchedule.map((schedule) => { | ||
const { startTime, endTime } = getScheduleStartAndEndTimes(schedule); | ||
|
||
const progress = ((Date.now() - startTime) / (endTime - startTime)) * 100; | ||
|
||
return progress > 10 ? progress : 10; | ||
}); | ||
|
||
return streamsProgress; | ||
}; |
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
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
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
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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Progress getStreamsProgress returns the progress of each stream 1`] = ` | ||
[ | ||
49.82118399026023, | ||
248.95437262357416, | ||
248.95437262357416, | ||
248.95437262357416, | ||
995.8174904942966, | ||
159.90424325672453, | ||
] | ||
`; |
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,12 @@ | ||
import { getStreamsProgress } from '../../../src/utils/progress'; | ||
import { streamsSchedule } from '../../fixtures/streams-schedule'; | ||
|
||
jest.useFakeTimers().setSystemTime(new Date('2024-11-12T00:00:00Z')); | ||
|
||
describe('Progress', () => { | ||
describe('getStreamsProgress', () => { | ||
it('returns the progress of each stream', () => { | ||
expect(getStreamsProgress(streamsSchedule)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { BigNumber } from 'ethers'; | ||
import { StreamSchedule } from '../../../src/types/stream'; | ||
import { getScheduleStartAndEndTimes } from '../../../src/utils/schedule'; | ||
|
||
const startTime = new Date('2024-01-01T00:00:00Z').getTime(); | ||
const endTime = new Date('2024-02-01T00:00:00Z').getTime(); | ||
|
||
describe('Schedule', () => { | ||
describe('getScheduleStartAndEndTimes', () => { | ||
it('throws if no times found', () => { | ||
const schedule: StreamSchedule = { | ||
scheduleTimes: [], | ||
scheduleRewards: [], | ||
}; | ||
|
||
expect(() => getScheduleStartAndEndTimes(schedule)).toThrow( | ||
'Invalid schedule: no schedule times found', | ||
); | ||
}); | ||
|
||
it('returns the start and end times', () => { | ||
const schedule: StreamSchedule = { | ||
scheduleTimes: [BigNumber.from(startTime), BigNumber.from(endTime)], | ||
scheduleRewards: [], | ||
}; | ||
|
||
expect(getScheduleStartAndEndTimes(schedule)).toEqual({ | ||
startTime: startTime * 1000, | ||
endTime: endTime * 1000, | ||
}); | ||
}); | ||
}); | ||
}); |
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