diff --git a/src/modules/atproto/infrastructure/services/FakeAtProtoOAuthProcessor.ts b/src/modules/atproto/infrastructure/services/FakeAtProtoOAuthProcessor.ts index 4664ebe6..41930804 100644 --- a/src/modules/atproto/infrastructure/services/FakeAtProtoOAuthProcessor.ts +++ b/src/modules/atproto/infrastructure/services/FakeAtProtoOAuthProcessor.ts @@ -11,8 +11,8 @@ export class FakeAtProtoOAuthProcessor implements IOAuthProcessor { async generateAuthUrl(handle?: string): Promise> { try { - // Generate tokens for the mock DID - const mockUrl = `http://127.0.0.1:3000/api/users/oauth/callback?code=mockCode&state=mockState&iss=mockIssuer`; + // Include the handle in the mock URL so we can identify which account to use + const mockUrl = `http://127.0.0.1:3000/api/users/oauth/callback?code=mockCode&state=mockState&iss=mockIssuer&handle=${encodeURIComponent(handle || '')}`; return ok(mockUrl); } catch (error: any) { return err(error); @@ -21,17 +21,49 @@ export class FakeAtProtoOAuthProcessor implements IOAuthProcessor { async processCallback(params: OAuthCallbackDTO): Promise> { try { - // Use mock data from environment variables - const mockDid = process.env.BSKY_DID || 'did:plc:mock123'; - const mockHandle = process.env.BSKY_HANDLE || 'mock.bsky.social'; - - // Simulate successful OAuth callback processing + // Extract handle from the callback params or use a default + const handle = (params as any).handle || this.getHandleFromState(params.state); + + // Get mock data based on handle + const mockData = this.getMockDataForHandle(handle); + return ok({ - did: mockDid, - handle: mockHandle, + did: mockData.did, + handle: mockData.handle, }); } catch (error: any) { return err(error); } } + + private getHandleFromState(state: string): string { + // In a real implementation, you'd decode the state to get the original handle + // For mock, we'll default to the first account + return process.env.BSKY_HANDLE_1 || 'alice.bsky.social'; + } + + private getMockDataForHandle(handle?: string): { did: string; handle: string } { + // Default to first account if no handle provided + if (!handle) { + return { + did: process.env.BSKY_DID_1 || 'did:plc:mock123', + handle: process.env.BSKY_HANDLE_1 || 'alice.bsky.social', + }; + } + + // Check if handle matches account 2 + const handle2 = process.env.BSKY_HANDLE_2 || 'bob.bsky.social'; + if (handle === handle2 || handle.includes('bob')) { + return { + did: process.env.BSKY_DID_2 || 'did:plc:mock456', + handle: handle2, + }; + } + + // Default to account 1 + return { + did: process.env.BSKY_DID_1 || 'did:plc:mock123', + handle: process.env.BSKY_HANDLE_1 || 'alice.bsky.social', + }; + } } diff --git a/src/modules/atproto/infrastructure/services/FakeBlueskyProfileService.ts b/src/modules/atproto/infrastructure/services/FakeBlueskyProfileService.ts index 480752c8..4c4c06f2 100644 --- a/src/modules/atproto/infrastructure/services/FakeBlueskyProfileService.ts +++ b/src/modules/atproto/infrastructure/services/FakeBlueskyProfileService.ts @@ -7,18 +7,15 @@ import { Result, ok, err } from 'src/shared/core/Result'; export class FakeBlueskyProfileService implements IProfileService { async getProfile(userId: string): Promise> { try { - // Use mock data from environment variables - const mockHandle = process.env.BSKY_HANDLE || 'mock.bsky.social'; - const mockDid = process.env.BSKY_DID || 'did:plc:mock123'; - - // Return mock profile data + // Determine which mock account to use based on userId (DID) + const mockData = this.getMockDataForUserId(userId); + const userProfile: UserProfile = { id: userId, - name: `Mock User`, - handle: mockHandle, - avatarUrl: - 'https://cdn.bsky.app/img/avatar/plain/did:plc:rlknsba2qldjkicxsmni3vyn/bafkreid4nmxspygkftep5b3m2wlcm3xvnwefkswzej7dhipojjxylkzfby@jpeg', - bio: 'This is a mock profile for testing purposes (https://semble.so/), made by @cosmik.network.', + name: mockData.name, + handle: mockData.handle, + avatarUrl: mockData.avatarUrl, + bio: mockData.bio, }; return ok(userProfile); @@ -30,4 +27,30 @@ export class FakeBlueskyProfileService implements IProfileService { ); } } + + private getMockDataForUserId(userId: string): { + name: string; + handle: string; + avatarUrl: string; + bio: string; + } { + const did2 = process.env.BSKY_DID_2 || 'did:plc:mock456'; + + if (userId === did2) { + return { + name: 'Mock User Bob', + handle: process.env.BSKY_HANDLE_2 || 'bob.bsky.social', + avatarUrl: 'https://cdn.bsky.app/img/avatar/plain/did:plc:rlknsba2qldjkicxsmni3vyn/bafkreid4nmxspygkftep5b3m2wlcm3xvnwefkswzej7dhipojjxylkzfby@jpeg', + bio: 'This is Bob - a second mock profile for testing purposes (https://semble.so/), made by @cosmik.network.', + }; + } + + // Default to account 1 + return { + name: 'Mock User Alice', + handle: process.env.BSKY_HANDLE_1 || 'alice.bsky.social', + avatarUrl: 'https://cdn.bsky.app/img/avatar/plain/did:plc:rlknsba2qldjkicxsmni3vyn/bafkreid4nmxspygkftep5b3m2wlcm3xvnwefkswzej7dhipojjxylkzfby@jpeg', + bio: 'This is Alice - a mock profile for testing purposes (https://semble.so/), made by @cosmik.network.', + }; + } } diff --git a/src/modules/user/infrastructure/services/FakeUserAuthenticationService.ts b/src/modules/user/infrastructure/services/FakeUserAuthenticationService.ts index b9bcae80..1d4307d9 100644 --- a/src/modules/user/infrastructure/services/FakeUserAuthenticationService.ts +++ b/src/modules/user/infrastructure/services/FakeUserAuthenticationService.ts @@ -18,25 +18,8 @@ export class FakeUserAuthenticationService handle?: Handle, ): Promise> { try { - // Use mock data from environment variables - const mockDid = process.env.BSKY_DID || 'did:plc:mock123'; - const mockHandle = process.env.BSKY_HANDLE || 'mock.bsky.social'; - - // Create mock DID and Handle - const mockDIDResult = DID.create(mockDid); - if (mockDIDResult.isErr()) { - return err(mockDIDResult.error); - } - - const mockHandleResult = Handle.create(mockHandle); - if (mockHandleResult.isErr()) { - return err(mockHandleResult.error); - } - - // Try to find existing user - const userResult = await this.userRepository.findByDID( - mockDIDResult.value, - ); + // Try to find existing user first + const userResult = await this.userRepository.findByDID(did); if (userResult.isErr()) { return err(userResult.error); @@ -52,11 +35,12 @@ export class FakeUserAuthenticationService }); } - // Create new user with mock data - const newUserResult = User.createNew( - mockDIDResult.value, - mockHandleResult.value, - ); + // Create new user with the provided DID and handle + if (!handle) { + return err(new Error('Handle is required for new user creation')); + } + + const newUserResult = User.createNew(did, handle); if (newUserResult.isErr()) { return err(newUserResult.error);