Skip to content

Conversation

@apsantiso
Copy link
Collaborator

@apsantiso apsantiso commented Oct 30, 2025

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

  • Replaced "created today" check with "created at or before most recent usage period" validation in addDailyUsageChangeOnFileSizeChange

@sonarqubecloud
Copy link

@apsantiso apsantiso requested a review from sg-gs October 30, 2025 10:48
@apsantiso apsantiso added the enhancement New feature or request label Oct 30, 2025
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');
Copy link
Member

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);
Copy link
Member

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(
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants