1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/lib/services/feature-service-potentially-stale.test.ts
Fredrik Strand Oseberg bc96216daa
Refactor/move features to feature oriented architecture (#4994)
This PR gathers feature related files in the same folder.
2023-10-11 09:38:57 +02:00

73 lines
2.7 KiB
TypeScript

import {
FEATURE_POTENTIALLY_STALE_ON,
IEvent,
IUnleashConfig,
IUnleashStores,
} from '../types';
import { createTestConfig } from '../../test/config/test-config';
import FeatureToggleService from '../features/feature-toggle/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';
import { IPrivateProjectChecker } from '../features/private-project/privateProjectCheckerType';
import { IDependentFeaturesReadModel } from '../features/dependent-features/dependent-features-read-model-type';
import EventService from './event-service';
import FakeFeatureTagStore from '../../test/fixtures/fake-feature-tag-store';
import { DependentFeaturesService } from '../features/dependent-features/dependent-features-service';
test('Should only store events for potentially stale on', async () => {
expect.assertions(2);
const featureUpdates = [
{ name: 'feature1', potentiallyStale: true, project: 'default' },
{ name: 'feature2', potentiallyStale: false, project: 'default' },
];
const config = createTestConfig();
const eventService = new EventService(
{
// @ts-expect-error
eventStore: {
batchStore: async (events: IEvent[]) => {
expect(events.length).toBe(1);
const [event1] = events;
expect(event1).toMatchObject({
featureName: 'feature1',
project: 'default',
type: FEATURE_POTENTIALLY_STALE_ON,
});
},
},
featureTagStore: new FakeFeatureTagStore(),
},
config,
);
const featureToggleService = new FeatureToggleService(
{
featureToggleStore: {
updatePotentiallyStaleFeatures: () => featureUpdates,
},
featureTagStore: {
getAllTagsForFeature: () => [],
},
} as unknown as IUnleashStores,
{
...config,
flagResolver: { isEnabled: () => true },
experimental: {
...(config.experimental ?? {}),
},
} as unknown as IUnleashConfig,
{} as ISegmentService,
{} as AccessService,
eventService,
{} as IChangeRequestAccessReadModel,
{} as IPrivateProjectChecker,
{} as IDependentFeaturesReadModel,
{} as DependentFeaturesService,
);
await featureToggleService.updatePotentiallyStaleFeatures();
});