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';
|
2023-10-11 09:38:57 +02:00
|
|
|
import FeatureToggleService from '../features/feature-toggle/feature-toggle-service';
|
2023-07-17 10:10:15 +02:00
|
|
|
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-09-15 14:52:54 +02:00
|
|
|
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
|
2023-09-27 15:07:20 +02:00
|
|
|
import { IDependentFeaturesReadModel } from '../features/dependent-features/dependent-features-read-model-type';
|
2023-09-27 15:23:05 +02:00
|
|
|
import EventService from './event-service';
|
|
|
|
import FakeFeatureTagStore from '../../test/fixtures/fake-feature-tag-store';
|
2023-10-04 12:20:27 +02:00
|
|
|
import { DependentFeaturesService } from '../features/dependent-features/dependent-features-service';
|
2023-07-17 10:10:15 +02:00
|
|
|
|
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();
|
2023-09-27 15:23:05 +02:00
|
|
|
const eventService = new EventService(
|
2023-07-17 10:10:15 +02:00
|
|
|
{
|
2023-09-27 15:23:05 +02:00
|
|
|
// @ts-expect-error
|
2023-07-17 10:10:15 +02:00
|
|
|
eventStore: {
|
2023-09-27 15:23:05 +02:00
|
|
|
batchStore: async (events: IEvent[]) => {
|
2023-07-19 15:20:18 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2023-09-27 15:23:05 +02:00
|
|
|
featureTagStore: new FakeFeatureTagStore(),
|
|
|
|
},
|
|
|
|
config,
|
|
|
|
);
|
|
|
|
|
|
|
|
const featureToggleService = new FeatureToggleService(
|
|
|
|
{
|
|
|
|
featureToggleStore: {
|
|
|
|
updatePotentiallyStaleFeatures: () => featureUpdates,
|
|
|
|
},
|
|
|
|
featureTagStore: {
|
|
|
|
getAllTagsForFeature: () => [],
|
|
|
|
},
|
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,
|
2023-09-27 15:23:05 +02:00
|
|
|
eventService,
|
2023-07-17 10:10:15 +02:00
|
|
|
{} as IChangeRequestAccessReadModel,
|
2023-09-15 14:52:54 +02:00
|
|
|
{} as IPrivateProjectChecker,
|
2023-09-27 15:07:20 +02:00
|
|
|
{} as IDependentFeaturesReadModel,
|
2023-10-04 12:20:27 +02:00
|
|
|
{} as DependentFeaturesService,
|
2023-07-17 10:10:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
await featureToggleService.updatePotentiallyStaleFeatures();
|
|
|
|
});
|