A social knowledge tool for researchers built on ATProto
45
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: convert mock repositories to singletons for consistent data sharing

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

+38 -8
+10
src/modules/cards/tests/utils/InMemoryCardRepository.ts
··· 6 6 import { URL } from '../../domain/value-objects/URL'; 7 7 8 8 export class InMemoryCardRepository implements ICardRepository { 9 + private static instance: InMemoryCardRepository; 9 10 private cards: Map<string, Card> = new Map(); 10 11 private shouldFail: boolean = false; 11 12 private shouldFailSave: boolean = false; 13 + 14 + private constructor() {} 15 + 16 + public static getInstance(): InMemoryCardRepository { 17 + if (!InMemoryCardRepository.instance) { 18 + InMemoryCardRepository.instance = new InMemoryCardRepository(); 19 + } 20 + return InMemoryCardRepository.instance; 21 + } 12 22 13 23 private clone(card: Card): Card { 14 24 // Simple clone - in a real implementation you'd want proper deep cloning
+10
src/modules/cards/tests/utils/InMemoryCollectionRepository.ts
··· 6 6 import { CuratorId } from '../../domain/value-objects/CuratorId'; 7 7 8 8 export class InMemoryCollectionRepository implements ICollectionRepository { 9 + private static instance: InMemoryCollectionRepository; 9 10 private collections: Map<string, Collection> = new Map(); 11 + 12 + private constructor() {} 13 + 14 + public static getInstance(): InMemoryCollectionRepository { 15 + if (!InMemoryCollectionRepository.instance) { 16 + InMemoryCollectionRepository.instance = new InMemoryCollectionRepository(); 17 + } 18 + return InMemoryCollectionRepository.instance; 19 + } 10 20 11 21 private clone(collection: Collection): Collection { 12 22 // Simple clone - in a real implementation you'd want proper deep cloning
+10
src/modules/user/tests/infrastructure/InMemoryUserRepository.ts
··· 4 4 import { DID } from '../../domain/value-objects/DID'; 5 5 6 6 export class InMemoryUserRepository implements IUserRepository { 7 + private static instance: InMemoryUserRepository; 7 8 private users: Map<string, User> = new Map(); 9 + 10 + private constructor() {} 11 + 12 + public static getInstance(): InMemoryUserRepository { 13 + if (!InMemoryUserRepository.instance) { 14 + InMemoryUserRepository.instance = new InMemoryUserRepository(); 15 + } 16 + return InMemoryUserRepository.instance; 17 + } 8 18 9 19 async findByDID(did: DID): Promise<Result<User | null>> { 10 20 try {
+8 -8
src/shared/infrastructure/http/factories/RepositoryFactory.ts
··· 55 55 const useMockRepos = process.env.USE_MOCK_REPOS === 'true'; 56 56 57 57 if (useMockRepos) { 58 - // Create in-memory repositories 59 - const userRepository = new InMemoryUserRepository(); 60 - const tokenRepository = new InMemoryTokenRepository(); 61 - const cardRepository = new InMemoryCardRepository(); 62 - const collectionRepository = new InMemoryCollectionRepository(); 58 + // Use singleton instances to ensure same data across processes 59 + const userRepository = InMemoryUserRepository.getInstance(); 60 + const tokenRepository = InMemoryTokenRepository.getInstance(); 61 + const cardRepository = InMemoryCardRepository.getInstance(); 62 + const collectionRepository = InMemoryCollectionRepository.getInstance(); 63 63 const cardQueryRepository = new InMemoryCardQueryRepository( 64 64 cardRepository, 65 65 collectionRepository, ··· 69 69 cardRepository, 70 70 ); 71 71 const appPasswordSessionRepository = 72 - new InMemoryAppPasswordSessionRepository(); 72 + InMemoryAppPasswordSessionRepository.getInstance(); 73 73 const feedRepository = InMemoryFeedRepository.getInstance(); 74 74 const atUriResolutionService = new InMemoryAtUriResolutionService( 75 75 collectionRepository, 76 76 ); 77 - const oauthStateStore = new InMemoryStateStore(); 78 - const oauthSessionStore = new InMemorySessionStore(); 77 + const oauthStateStore = InMemoryStateStore.getInstance(); 78 + const oauthSessionStore = InMemorySessionStore.getInstance(); 79 79 80 80 return { 81 81 userRepository,