Skip to content

Commit

Permalink
feat: export transactional user subscriptions service (#8651)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Nov 5, 2024
1 parent 1cedc37 commit b5a2bef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/lib/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './instance-stats/createInstanceStatsService';
export * from './feature-lifecycle/createFeatureLifecycle';
export * from './playground/createPlaygroundService';
export * from './personal-dashboard/createPersonalDashboardService';
export * from './user-subscriptions/createUserSubscriptionsService';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Db, IUnleashConfig } from '../../server-impl';
import UserSubscriptionService from './user-subscriptions-service';
import { UserSubscriptionsService } from './user-subscriptions-service';
import { UserUnsubscribeStore } from './user-unsubscribe-store';
import {
createEventsService,
Expand All @@ -9,11 +9,11 @@ import { FakeUserUnsubscribeStore } from './fake-user-unsubscribe-store';

export const createUserSubscriptionsService =
(config: IUnleashConfig) =>
(db: Db): UserSubscriptionService => {
(db: Db): UserSubscriptionsService => {
const userUnsubscribeStore = new UserUnsubscribeStore(db);
const eventService = createEventsService(db, config);

const userSubscriptionsService = new UserSubscriptionService(
const userSubscriptionsService = new UserSubscriptionsService(
{ userUnsubscribeStore },
config,
eventService,
Expand All @@ -22,11 +22,13 @@ export const createUserSubscriptionsService =
return userSubscriptionsService;
};

export const createFakeUserSubscriptionsService = (config: IUnleashConfig) => {
export const createFakeUserSubscriptionsService = (
config: IUnleashConfig,
): UserSubscriptionsService => {
const userUnsubscribeStore = new FakeUserUnsubscribeStore();
const eventService = createFakeEventsService(config);

const userSubscriptionsService = new UserSubscriptionService(
const userSubscriptionsService = new UserSubscriptionsService(
{ userUnsubscribeStore },
config,
eventService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type IUser,
TEST_AUDIT_USER,
} from '../../types';
import type UserSubscriptionService from './user-subscriptions-service';
import type { UserSubscriptionsService } from './user-subscriptions-service';
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
import { createTestConfig } from '../../../test/config/test-config';
import getLogger from '../../../test/fixtures/no-logger';
Expand All @@ -13,7 +13,7 @@ import type { IUserSubscriptionsReadModel } from './user-subscriptions-read-mode

let stores: IUnleashStores;
let db: ITestDb;
let userSubscriptionService: UserSubscriptionService;
let userSubscriptionService: UserSubscriptionsService;
let userSubscriptionsReadModel: IUserSubscriptionsReadModel;
let config: IUnleashConfig;
let user: IUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from './user-unsubscribe-store-type';
import type EventService from '../events/event-service';

export default class UserSubscriptionService {
export class UserSubscriptionsService {
private userUnsubscribeStore: IUserUnsubscribeStore;

private eventService: EventService;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ import {
createFakeEnvironmentService,
createFakeEventsService,
createFakeProjectService,
createFakeUserSubscriptionsService,
createFeatureLifecycleService,
createFeatureToggleService,
createProjectService,
createUserSubscriptionsService,
} from '../features';
import EventAnnouncerService from './event-announcer-service';
import { createGroupService } from '../features/group/createGroupService';
Expand Down Expand Up @@ -127,6 +129,7 @@ import {
createProjectInsightsService,
} from '../features/project-insights/createProjectInsightsService';
import { JobService } from '../features/scheduler/job-service';
import { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service';
import { JobStore } from '../features/scheduler/job-store';
import { FeatureLifecycleService } from '../features/feature-lifecycle/feature-lifecycle-service';
import { createFakeFeatureLifecycleService } from '../features/feature-lifecycle/createFeatureLifecycle';
Expand Down Expand Up @@ -426,6 +429,10 @@ export const createServices = (
? createPersonalDashboardService(db, config, stores)
: createFakePersonalDashboardService(config);

const transactionalUserSubscriptionsService = db
? withTransactional(createUserSubscriptionsService(config), db)
: withFakeTransactional(createFakeUserSubscriptionsService(config));

return {
transactionalAccessService,
accessService,
Expand Down Expand Up @@ -492,6 +499,7 @@ export const createServices = (
onboardingService,
personalDashboardService,
projectStatusService,
transactionalUserSubscriptionsService,
};
};

Expand Down Expand Up @@ -544,4 +552,5 @@ export {
OnboardingService,
PersonalDashboardService,
ProjectStatusService,
UserSubscriptionsService,
};
2 changes: 2 additions & 0 deletions src/lib/types/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import type { IntegrationEventsService } from '../features/integration-events/in
import type { OnboardingService } from '../features/onboarding/onboarding-service';
import type { PersonalDashboardService } from '../features/personal-dashboard/personal-dashboard-service';
import type { ProjectStatusService } from '../features/project-status/project-status-service';
import type { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service';

export interface IUnleashServices {
transactionalAccessService: WithTransactional<AccessService>;
Expand Down Expand Up @@ -128,4 +129,5 @@ export interface IUnleashServices {
onboardingService: OnboardingService;
personalDashboardService: PersonalDashboardService;
projectStatusService: ProjectStatusService;
transactionalUserSubscriptionsService: WithTransactional<UserSubscriptionsService>;
}

0 comments on commit b5a2bef

Please sign in to comment.