diff --git a/src/lib/features/events/event-service.ts b/src/lib/features/events/event-service.ts index a64328b67f..6ec7d4b5e2 100644 --- a/src/lib/features/events/event-service.ts +++ b/src/lib/features/events/event-service.ts @@ -13,6 +13,7 @@ import { ApiTokenType } from '../../types/models/api-token'; import { EVENTS_CREATED_BY_PROCESSED } from '../../metric-events'; import type { IQueryParam } from '../feature-toggle/types/feature-toggle-strategies-store-type'; import { parseSearchOperatorValue } from '../feature-search/search-utils'; +import { endOfDay, formatISO } from 'date-fns'; export default class EventService { private logger: Logger; @@ -158,7 +159,13 @@ export default class EventService { } if (params.to) { - const parsed = parseSearchOperatorValue('created_at', params.to); + const parsed = parseSearchOperatorValue( + 'created_at', + formatISO(endOfDay(new Date(params.to)), { + representation: 'date', + }), + ); + if (parsed) { queryParams.push({ field: parsed.field, diff --git a/src/test/e2e/api/admin/event-search.e2e.test.ts b/src/test/e2e/api/admin/event-search.e2e.test.ts index d16e5a69f6..7856434c6d 100644 --- a/src/test/e2e/api/admin/event-search.e2e.test.ts +++ b/src/test/e2e/api/admin/event-search.e2e.test.ts @@ -246,6 +246,33 @@ test('should filter events by created date range', async () => { }); }); +test('should include dates created on the `to` date', async () => { + await eventService.storeEvent({ + type: FEATURE_CREATED, + project: 'default', + data: { featureName: 'my_feature_b' }, + createdBy: 'test-user', + createdByUserId: TEST_USER_ID, + ip: '127.0.0.1', + }); + + const today = new Date(); + + const { body } = await searchEvents({ + to: `IS:${today.toISOString().split('T')[0]}`, + }); + + expect(body).toMatchObject({ + events: [ + { + type: FEATURE_CREATED, + data: { featureName: 'my_feature_b' }, + }, + ], + total: 1, + }); +}); + test('should paginate with offset and limit', async () => { for (let i = 0; i < 5; i++) { await eventService.storeEvent({