1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: segments service DI (#4376)

This commit is contained in:
Mateusz Kwasniewski 2023-08-01 11:20:59 +02:00 committed by GitHub
parent 579b08be27
commit da5e18233c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -3,3 +3,4 @@ export * from './export-import-toggles/createExportImportService';
export * from './feature-toggle/createFeatureToggleService';
export * from './project/createProjectService';
export * from './change-request-access-service/createChangeRequestAccessReadModel';
export * from './segment/createSegmentService';

View File

@ -0,0 +1,47 @@
import { Db, IUnleashConfig } from 'lib/server-impl';
import EventStore from '../../db/event-store';
import { SegmentService } from '../../services';
import FakeEventStore from '../../../test/fixtures/fake-event-store';
import { ISegmentService } from '../../segments/segment-service-interface';
import FeatureStrategiesStore from '../../db/feature-strategy-store';
import SegmentStore from '../../db/segment-store';
import FakeSegmentStore from '../../../test/fixtures/fake-segment-store';
import FakeFeatureStrategiesStore from '../../../test/fixtures/fake-feature-strategies-store';
export const createSegmentService = (
db: Db,
config: IUnleashConfig,
): ISegmentService => {
const { eventBus, getLogger, flagResolver } = config;
const eventStore = new EventStore(db, getLogger);
const segmentStore = new SegmentStore(
db,
eventBus,
getLogger,
flagResolver,
);
const featureStrategiesStore = new FeatureStrategiesStore(
db,
eventBus,
getLogger,
flagResolver,
);
return new SegmentService(
{ segmentStore, featureStrategiesStore, eventStore },
config,
);
};
export const createFakeSegmentService = (
config: IUnleashConfig,
): ISegmentService => {
const eventStore = new FakeEventStore();
const segmentStore = new FakeSegmentStore();
const featureStrategiesStore = new FakeFeatureStrategiesStore();
return new SegmentService(
{ segmentStore, featureStrategiesStore, eventStore },
config,
);
};