2023-07-19 15:20:18 +02:00
|
|
|
import {
|
|
|
|
FEATURE_POTENTIALLY_STALE_ON,
|
|
|
|
IEvent,
|
|
|
|
IUnleashConfig,
|
|
|
|
IUnleashStores,
|
|
|
|
} from '../types';
|
2023-07-17 10:10:15 +02:00
|
|
|
import { createTestConfig } from '../../test/config/test-config';
|
|
|
|
import FeatureToggleService from './feature-toggle-service';
|
|
|
|
import { AccessService } from './access-service';
|
|
|
|
import { IChangeRequestAccessReadModel } from 'lib/features/change-request-access-service/change-request-access-read-model';
|
|
|
|
import { ISegmentService } from 'lib/segments/segment-service-interface';
|
|
|
|
|
2023-07-19 15:20:18 +02:00
|
|
|
test('Should only store events for potentially stale on', async () => {
|
|
|
|
expect.assertions(2);
|
2023-07-17 10:10:15 +02:00
|
|
|
const featureUpdates = [
|
2023-07-19 15:20:18 +02:00
|
|
|
{ name: 'feature1', potentiallyStale: true, project: 'default' },
|
|
|
|
{ name: 'feature2', potentiallyStale: false, project: 'default' },
|
2023-07-17 10:10:15 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const config = createTestConfig();
|
|
|
|
const featureToggleService = new FeatureToggleService(
|
|
|
|
{
|
|
|
|
featureToggleStore: {
|
|
|
|
updatePotentiallyStaleFeatures: () => featureUpdates,
|
|
|
|
},
|
2023-07-19 15:20:18 +02:00
|
|
|
featureTagStore: {
|
|
|
|
getAllTagsForFeature: () => [],
|
|
|
|
},
|
2023-07-17 10:10:15 +02:00
|
|
|
eventStore: {
|
2023-07-19 15:20:18 +02:00
|
|
|
batchStore: (events: IEvent[]) => {
|
|
|
|
expect(events.length).toBe(1);
|
|
|
|
const [event1] = events;
|
|
|
|
|
|
|
|
expect(event1).toMatchObject({
|
|
|
|
featureName: 'feature1',
|
|
|
|
project: 'default',
|
|
|
|
type: FEATURE_POTENTIALLY_STALE_ON,
|
2023-07-17 10:10:15 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} as unknown as IUnleashStores,
|
|
|
|
{
|
|
|
|
...config,
|
|
|
|
flagResolver: { isEnabled: () => true },
|
|
|
|
experimental: {
|
|
|
|
...(config.experimental ?? {}),
|
|
|
|
},
|
|
|
|
} as unknown as IUnleashConfig,
|
|
|
|
{} as ISegmentService,
|
|
|
|
{} as AccessService,
|
|
|
|
{} as IChangeRequestAccessReadModel,
|
|
|
|
);
|
|
|
|
|
|
|
|
await featureToggleService.updatePotentiallyStaleFeatures();
|
|
|
|
});
|