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:
parent
2556bd0cf6
commit
440d6b48db
@ -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,
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user