fix(core): Handle infinite max history for insights date range (#14794)

This commit is contained in:
Guillaume Jacquart
2025-04-22 17:44:28 +02:00
committed by GitHub
parent f835c66d98
commit e83a64b84a
2 changed files with 20 additions and 1 deletions

View File

@@ -505,6 +505,22 @@ describe('getAvailableDateRanges', () => {
);
});
test('returns correct ranges when hourly data is enabled and max history is unlimited', () => {
licenseMock.getInsightsMaxHistory.mockReturnValue(-1);
licenseMock.isInsightsHourlyDataEnabled.mockReturnValue(true);
const result = insightsService.getAvailableDateRanges();
expect(result).toEqual([
{ key: 'day', licensed: true, granularity: 'hour' },
{ key: 'week', licensed: true, granularity: 'day' },
{ key: '2weeks', licensed: true, granularity: 'day' },
{ key: 'month', licensed: true, granularity: 'day' },
{ key: 'quarter', licensed: true, granularity: 'week' },
{ key: 'year', licensed: true, granularity: 'week' },
]);
});
test('returns correct ranges when hourly data is enabled and max history is 365 days', () => {
licenseMock.getInsightsMaxHistory.mockReturnValue(365);
licenseMock.isInsightsHourlyDataEnabled.mockReturnValue(true);

View File

@@ -182,7 +182,10 @@ export class InsightsService {
}
getAvailableDateRanges(): InsightsDateRange[] {
const maxHistoryInDays = this.license.getInsightsMaxHistory();
const maxHistoryInDays =
this.license.getInsightsMaxHistory() === -1
? Number.MAX_SAFE_INTEGER
: this.license.getInsightsMaxHistory();
const isHourlyDateEnabled = this.license.isInsightsHourlyDataEnabled();
return [