mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
chore: composition root playground service (#7710)
This commit is contained in:
parent
126dff2344
commit
987ba5ea0a
@ -10,3 +10,4 @@ export * from './project-environments/createEnvironmentService';
|
|||||||
export * from './events/createEventsService';
|
export * from './events/createEventsService';
|
||||||
export * from './instance-stats/createInstanceStatsService';
|
export * from './instance-stats/createInstanceStatsService';
|
||||||
export * from './feature-lifecycle/createFeatureLifecycle';
|
export * from './feature-lifecycle/createFeatureLifecycle';
|
||||||
|
export * from './playground/createPlaygroundService';
|
||||||
|
50
src/lib/features/playground/createPlaygroundService.ts
Normal file
50
src/lib/features/playground/createPlaygroundService.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import type { Db, IUnleashConfig } from '../../server-impl';
|
||||||
|
import { PlaygroundService } from './playground-service';
|
||||||
|
import {
|
||||||
|
createFakeFeatureToggleService,
|
||||||
|
createFeatureToggleService,
|
||||||
|
} from '../feature-toggle/createFeatureToggleService';
|
||||||
|
import {
|
||||||
|
createFakePrivateProjectChecker,
|
||||||
|
createPrivateProjectChecker,
|
||||||
|
} from '../private-project/createPrivateProjectChecker';
|
||||||
|
import { SegmentReadModel } from '../segment/segment-read-model';
|
||||||
|
import { FakeSegmentReadModel } from '../segment/fake-segment-read-model';
|
||||||
|
|
||||||
|
export const createPlaygroundService = (
|
||||||
|
db: Db,
|
||||||
|
config: IUnleashConfig,
|
||||||
|
): PlaygroundService => {
|
||||||
|
const segmentReadModel = new SegmentReadModel(db);
|
||||||
|
const privateProjectChecker = createPrivateProjectChecker(db, config);
|
||||||
|
const featureToggleServiceV2 = createFeatureToggleService(db, config);
|
||||||
|
|
||||||
|
const playgroundService = new PlaygroundService(
|
||||||
|
config,
|
||||||
|
{
|
||||||
|
featureToggleServiceV2,
|
||||||
|
privateProjectChecker,
|
||||||
|
},
|
||||||
|
segmentReadModel,
|
||||||
|
);
|
||||||
|
|
||||||
|
return playgroundService;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createFakePlaygroundService = (config: IUnleashConfig) => {
|
||||||
|
const segmentReadModel = new FakeSegmentReadModel();
|
||||||
|
const privateProjectChecker = createFakePrivateProjectChecker();
|
||||||
|
const featureToggleServiceV2 =
|
||||||
|
createFakeFeatureToggleService(config).featureToggleService;
|
||||||
|
|
||||||
|
const playgroundService = new PlaygroundService(
|
||||||
|
config,
|
||||||
|
{
|
||||||
|
featureToggleServiceV2,
|
||||||
|
privateProjectChecker,
|
||||||
|
},
|
||||||
|
segmentReadModel,
|
||||||
|
);
|
||||||
|
|
||||||
|
return playgroundService;
|
||||||
|
};
|
@ -1,7 +1,7 @@
|
|||||||
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
|
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
|
||||||
import {
|
import {
|
||||||
type IUnleashTest,
|
type IUnleashTest,
|
||||||
setupApp,
|
setupAppWithCustomConfig,
|
||||||
} from '../../../test/e2e/helpers/test-helper';
|
} from '../../../test/e2e/helpers/test-helper';
|
||||||
import type { IUnleashStores } from '../../types';
|
import type { IUnleashStores } from '../../types';
|
||||||
import getLogger from '../../../test/fixtures/no-logger';
|
import getLogger from '../../../test/fixtures/no-logger';
|
||||||
@ -23,7 +23,7 @@ beforeAll(async () => {
|
|||||||
|
|
||||||
await stores.featureToggleStore.create('default', flag);
|
await stores.featureToggleStore.create('default', flag);
|
||||||
|
|
||||||
app = await setupApp(stores);
|
app = await setupAppWithCustomConfig(stores, {}, db.rawDatabase);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -137,6 +137,10 @@ import {
|
|||||||
import { IntegrationEventsService } from '../features/integration-events/integration-events-service';
|
import { IntegrationEventsService } from '../features/integration-events/integration-events-service';
|
||||||
import { FeatureCollaboratorsReadModel } from '../features/feature-toggle/feature-collaborators-read-model';
|
import { FeatureCollaboratorsReadModel } from '../features/feature-toggle/feature-collaborators-read-model';
|
||||||
import { FakeFeatureCollaboratorsReadModel } from '../features/feature-toggle/fake-feature-collaborators-read-model';
|
import { FakeFeatureCollaboratorsReadModel } from '../features/feature-toggle/fake-feature-collaborators-read-model';
|
||||||
|
import {
|
||||||
|
createFakePlaygroundService,
|
||||||
|
createPlaygroundService,
|
||||||
|
} from '../features/playground/createPlaygroundService';
|
||||||
|
|
||||||
export const createServices = (
|
export const createServices = (
|
||||||
stores: IUnleashStores,
|
stores: IUnleashStores,
|
||||||
@ -319,14 +323,9 @@ export const createServices = (
|
|||||||
const userSplashService = new UserSplashService(stores, config);
|
const userSplashService = new UserSplashService(stores, config);
|
||||||
const openApiService = new OpenApiService(config);
|
const openApiService = new OpenApiService(config);
|
||||||
const clientSpecService = new ClientSpecService(config);
|
const clientSpecService = new ClientSpecService(config);
|
||||||
const playgroundService = new PlaygroundService(
|
const playgroundService = db
|
||||||
config,
|
? createPlaygroundService(db, config)
|
||||||
{
|
: createFakePlaygroundService(config);
|
||||||
featureToggleServiceV2,
|
|
||||||
privateProjectChecker,
|
|
||||||
},
|
|
||||||
segmentReadModel,
|
|
||||||
);
|
|
||||||
|
|
||||||
const configurationRevisionService =
|
const configurationRevisionService =
|
||||||
ConfigurationRevisionService.getInstance(stores, config);
|
ConfigurationRevisionService.getInstance(stores, config);
|
||||||
|
@ -2,7 +2,10 @@ import fc, { type Arbitrary } from 'fast-check';
|
|||||||
import { clientFeature, clientFeatures } from '../../../arbitraries.test';
|
import { clientFeature, clientFeatures } from '../../../arbitraries.test';
|
||||||
import { generate as generateRequest } from '../../../../lib/openapi/spec/playground-request-schema.test';
|
import { generate as generateRequest } from '../../../../lib/openapi/spec/playground-request-schema.test';
|
||||||
import dbInit, { type ITestDb } from '../../helpers/database-init';
|
import dbInit, { type ITestDb } from '../../helpers/database-init';
|
||||||
import { type IUnleashTest, setupAppWithAuth } from '../../helpers/test-helper';
|
import {
|
||||||
|
type IUnleashTest,
|
||||||
|
setupAppWithCustomConfig,
|
||||||
|
} from '../../helpers/test-helper';
|
||||||
import { type FeatureToggle, WeightType } from '../../../../lib/types/model';
|
import { type FeatureToggle, WeightType } from '../../../../lib/types/model';
|
||||||
import getLogger from '../../../fixtures/no-logger';
|
import getLogger from '../../../fixtures/no-logger';
|
||||||
import {
|
import {
|
||||||
@ -21,7 +24,7 @@ let token: IApiToken;
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
db = await dbInit('playground_api_serial', getLogger);
|
db = await dbInit('playground_api_serial', getLogger);
|
||||||
app = await setupAppWithAuth(db.stores);
|
app = await setupAppWithCustomConfig(db.stores, {}, db.rawDatabase);
|
||||||
const { apiTokenService } = app.services;
|
const { apiTokenService } = app.services;
|
||||||
token = await apiTokenService.createApiTokenWithProjects({
|
token = await apiTokenService.createApiTokenWithProjects({
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
|
Loading…
Reference in New Issue
Block a user