1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: make to date inclusive (#7775)

Changes the handling of the `to` query parameter in
the API to be inclusive.
This commit is contained in:
Thomas Heartman 2024-08-06 15:40:07 +02:00 committed by GitHub
parent 2556bd0cf6
commit 440d6b48db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -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,

View File

@ -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({