1
0
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:
Mateusz Kwasniewski 2024-07-31 14:44:57 +02:00 committed by GitHub
parent 126dff2344
commit 987ba5ea0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 65 additions and 12 deletions

View File

@ -10,3 +10,4 @@ export * from './project-environments/createEnvironmentService';
export * from './events/createEventsService';
export * from './instance-stats/createInstanceStatsService';
export * from './feature-lifecycle/createFeatureLifecycle';
export * from './playground/createPlaygroundService';

View 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;
};

View File

@ -1,7 +1,7 @@
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
import {
type IUnleashTest,
setupApp,
setupAppWithCustomConfig,
} from '../../../test/e2e/helpers/test-helper';
import type { IUnleashStores } from '../../types';
import getLogger from '../../../test/fixtures/no-logger';
@ -23,7 +23,7 @@ beforeAll(async () => {
await stores.featureToggleStore.create('default', flag);
app = await setupApp(stores);
app = await setupAppWithCustomConfig(stores, {}, db.rawDatabase);
});
afterAll(async () => {

View File

@ -137,6 +137,10 @@ import {
import { IntegrationEventsService } from '../features/integration-events/integration-events-service';
import { FeatureCollaboratorsReadModel } from '../features/feature-toggle/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 = (
stores: IUnleashStores,
@ -319,14 +323,9 @@ export const createServices = (
const userSplashService = new UserSplashService(stores, config);
const openApiService = new OpenApiService(config);
const clientSpecService = new ClientSpecService(config);
const playgroundService = new PlaygroundService(
config,
{
featureToggleServiceV2,
privateProjectChecker,
},
segmentReadModel,
);
const playgroundService = db
? createPlaygroundService(db, config)
: createFakePlaygroundService(config);
const configurationRevisionService =
ConfigurationRevisionService.getInstance(stores, config);

View File

@ -2,7 +2,10 @@ import fc, { type Arbitrary } from 'fast-check';
import { clientFeature, clientFeatures } from '../../../arbitraries.test';
import { generate as generateRequest } from '../../../../lib/openapi/spec/playground-request-schema.test';
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 getLogger from '../../../fixtures/no-logger';
import {
@ -21,7 +24,7 @@ let token: IApiToken;
beforeAll(async () => {
db = await dbInit('playground_api_serial', getLogger);
app = await setupAppWithAuth(db.stores);
app = await setupAppWithCustomConfig(db.stores, {}, db.rawDatabase);
const { apiTokenService } = app.services;
token = await apiTokenService.createApiTokenWithProjects({
type: ApiTokenType.ADMIN,