-
Notifications
You must be signed in to change notification settings - Fork 4
[_] fix(usage): fix daily usage when there is a gap between monthly usages #769
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
Conversation
d6f1499 to
30e5052
Compare
30e5052 to
2d39d7c
Compare
|
| const todayFile = newFile({ | ||
| it('When file was created before usage period and size increased, then should create daily usage with positive delta', async () => { | ||
| const usagePeriod = new Date('2024-06-15T00:00:00.000Z'); | ||
| const dateBeforeUsage = new Date('2024-06-10T00:00:00.000Z'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's subtract the days with dayjs from the usagePeriod
| // Files created the same day do not need a daily usage entry, they will be included in the next monthly usage | ||
| const isFileCreatedToday = Time.isToday(newFileData.createdAt); | ||
| const recentUsage = | ||
| await this.usageRepository.getMostRecentMonthlyOrYearlyUsage(user.uuid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Monthly should be daily as we talked
| .spyOn(usageRepository, 'getMostRecentMonthlyOrYearlyUsage') | ||
| .mockResolvedValue(existingUsage); | ||
|
|
||
| const result = await service.addDailyUsageChangeOnFileSizeChange( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function may return void as it 'adds' things, otherwise the naming may be wrong



Fixes daily usage calculation when there is a gap between monthly usages. Files created after the most recent usage period should not generate daily usage entries, as they will be included in the next monthly calculation.
Changes
addDailyUsageChangeOnFileSizeChange