Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export transactional user subscriptions service #8651

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}