A social knowledge tool for researchers built on ATProto
at development 45 lines 1.1 kB view raw
1import { 2 IProfileService, 3 UserProfile, 4} from '../../domain/services/IProfileService'; 5import { Result, ok, err } from '../../../../shared/core/Result'; 6 7export class FakeProfileService implements IProfileService { 8 private profiles: Map<string, UserProfile> = new Map(); 9 private shouldFail: boolean = false; 10 11 async getProfile(userId: string): Promise<Result<UserProfile>> { 12 if (this.shouldFail) { 13 return err(new Error('Simulated profile service failure')); 14 } 15 16 const profile = this.profiles.get(userId); 17 if (!profile) { 18 return err(new Error(`Profile not found for user: ${userId}`)); 19 } 20 21 return ok(profile); 22 } 23 24 // Test helper methods 25 addProfile(profile: UserProfile): void { 26 this.profiles.set(profile.id, profile); 27 } 28 29 setShouldFail(shouldFail: boolean): void { 30 this.shouldFail = shouldFail; 31 } 32 33 clear(): void { 34 this.profiles.clear(); 35 this.shouldFail = false; 36 } 37 38 getStoredProfile(userId: string): UserProfile | undefined { 39 return this.profiles.get(userId); 40 } 41 42 getAllProfiles(): UserProfile[] { 43 return Array.from(this.profiles.values()); 44 } 45}