From f3b0b05bc4581d7a6347f704efbc41a601230acb Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 19 Mar 2026 15:06:47 -0700 Subject: [PATCH] in mem events and repo working with connections --- .../infrastructure/InMemoryFeedRepository.ts | 27 ++++++++++++++++--- .../processes/InMemoryEventWorkerProcess.ts | 10 +++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/modules/feeds/tests/infrastructure/InMemoryFeedRepository.ts b/src/modules/feeds/tests/infrastructure/InMemoryFeedRepository.ts index 2dd3d42b..b0d24b4d 100644 --- a/src/modules/feeds/tests/infrastructure/InMemoryFeedRepository.ts +++ b/src/modules/feeds/tests/infrastructure/InMemoryFeedRepository.ts @@ -44,9 +44,16 @@ export class InMemoryFeedRepository implements IFeedRepository { options: FeedQueryOptions, ): Promise> { try { - const { page, limit, beforeActivityId, urlType } = options; + const { page, limit, beforeActivityId, urlType, activityTypes } = options; let filteredActivities = [...this.activities]; + // Filter by activity types if provided + if (activityTypes && activityTypes.length > 0) { + filteredActivities = filteredActivities.filter((activity) => + activityTypes.includes(activity.type.value), + ); + } + // Filter by URL type if provided if (urlType) { filteredActivities = filteredActivities.filter( @@ -96,7 +103,7 @@ export class InMemoryFeedRepository implements IFeedRepository { options: FeedQueryOptions, ): Promise> { try { - const { page, limit, beforeActivityId, urlType } = options; + const { page, limit, beforeActivityId, urlType, activityTypes } = options; const collectionIdStrings = collectionIds.map((id) => id.getStringValue(), ); @@ -114,6 +121,13 @@ export class InMemoryFeedRepository implements IFeedRepository { return false; }); + // Filter by activity types if provided + if (activityTypes && activityTypes.length > 0) { + filteredActivities = filteredActivities.filter((activity) => + activityTypes.includes(activity.type.value), + ); + } + // Filter by URL type if provided if (urlType) { filteredActivities = filteredActivities.filter( @@ -244,7 +258,7 @@ export class InMemoryFeedRepository implements IFeedRepository { options: FeedQueryOptions, ): Promise> { try { - const { page, limit, beforeActivityId, urlType } = options; + const { page, limit, beforeActivityId, urlType, activityTypes } = options; // Get activity IDs for this user's following feed const userActivityIds = this.followingFeedItems.get(userId) || new Set(); @@ -254,6 +268,13 @@ export class InMemoryFeedRepository implements IFeedRepository { userActivityIds.has(activity.activityId.getStringValue()), ); + // Filter by activity types if provided + if (activityTypes && activityTypes.length > 0) { + filteredActivities = filteredActivities.filter((activity) => + activityTypes.includes(activity.type.value), + ); + } + // Filter by URL type if provided if (urlType) { filteredActivities = filteredActivities.filter( diff --git a/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts b/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts index 9b0d206b..7833cde8 100644 --- a/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts +++ b/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts @@ -21,6 +21,7 @@ import { RepositoryFactory, Repositories, } from '../http/factories/RepositoryFactory'; +import { ConnectionCreatedEventHandler } from 'src/modules/feeds/application/eventHandlers/ConnectionCreatedEventHandler'; export class InMemoryEventWorkerProcess implements IProcess { constructor(private configService: EnvironmentConfigService) {} @@ -102,6 +103,10 @@ export class InMemoryEventWorkerProcess implements IProcess { repositories.notificationRepository, ); + const connectionCreatedHandler = new ConnectionCreatedEventHandler( + useCases.addActivityToFeedUseCase, + ); + // Register feed handlers await subscriber.subscribe( EventNames.CARD_ADDED_TO_LIBRARY, @@ -152,5 +157,10 @@ export class InMemoryEventWorkerProcess implements IProcess { EventNames.USER_UNFOLLOWED_TARGET, userUnfollowedTargetHandler, ); + + await subscriber.subscribe( + EventNames.CONNECTION_CREATED, + connectionCreatedHandler, + ); } } -- 2.51.2