From a66a4a09ee90820edaf9b032ced07d0399530f86 Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Wed, 1 Oct 2025 15:58:04 -0700 Subject: [PATCH] feat: implement resolveToHandle method in FakeIdentityResolutionService Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) --- .../utils/FakeIdentityResolutionService.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/modules/cards/tests/utils/FakeIdentityResolutionService.ts b/src/modules/cards/tests/utils/FakeIdentityResolutionService.ts index 86d87db7..f612f676 100644 --- a/src/modules/cards/tests/utils/FakeIdentityResolutionService.ts +++ b/src/modules/cards/tests/utils/FakeIdentityResolutionService.ts @@ -2,11 +2,13 @@ import { Result, ok, err } from 'src/shared/core/Result'; import { IIdentityResolutionService } from 'src/modules/atproto/domain/services/IIdentityResolutionService'; import { DID } from 'src/modules/atproto/domain/DID'; import { DIDOrHandle } from 'src/modules/atproto/domain/DIDOrHandle'; +import { Handle } from 'src/modules/atproto/domain/Handle'; export class FakeIdentityResolutionService implements IIdentityResolutionService { private handleToDIDMap: Map = new Map(); + private didToHandleMap: Map = new Map(); private shouldFail = false; async resolveToDID(identifier: DIDOrHandle): Promise> { @@ -54,9 +56,55 @@ export class FakeIdentityResolutionService } } + async resolveToHandle(identifier: DIDOrHandle): Promise> { + if (this.shouldFail) { + return err(new Error('Identity resolution service failed')); + } + + try { + // If it's already a handle, return it directly + if (identifier.isHandle) { + const handle = identifier.getHandle(); + if (!handle) { + return err(new Error('Invalid handle in identifier')); + } + return ok(handle); + } + + // If it's a DID, resolve it to a handle + const did = identifier.getDID(); + if (!did) { + return err(new Error('Invalid DID in identifier')); + } + + // Check if we have a mapping for this DID + const mappedHandle = this.didToHandleMap.get(did.value); + if (!mappedHandle) { + return err(new Error(`DID not found: ${did.value}`)); + } + + // Create and return the Handle + const handleResult = Handle.create(mappedHandle); + if (handleResult.isErr()) { + return err( + new Error(`Invalid handle in mapping: ${handleResult.error.message}`), + ); + } + + return ok(handleResult.value); + } catch (error) { + return err( + new Error( + `Error resolving identifier to handle: ${error instanceof Error ? error.message : String(error)}`, + ), + ); + } + } + // Test helper methods addHandleMapping(handle: string, did: string): void { this.handleToDIDMap.set(handle, did); + this.didToHandleMap.set(did, handle); } setShouldFail(shouldFail: boolean): void { @@ -65,6 +113,7 @@ export class FakeIdentityResolutionService clear(): void { this.handleToDIDMap.clear(); + this.didToHandleMap.clear(); this.shouldFail = false; } } -- 2.51.2