import Foundation import Testing @testable import CoreATProtocol @Suite("DID resolver") struct DIDResolverTests { @Test("Documents yield the PDS endpoint and the claimed handle") func parseDocument() throws { let body = Data(""" {"id":"did:plc:abc","alsoKnownAs":["at://alice.test"],"service":[{"id":"#atproto_pds","type":"AtprotoPersonalDataServer","serviceEndpoint":"https://pds.example.com"}]} """.utf8) let document = try DIDResolver.parse(documentData: body, expecting: "did:plc:abc") #expect(document.handle == "alice.test") #expect(document.pdsEndpoint == "https://pds.example.com") #expect(throws: DIDResolver.ResolutionError.documentMismatch(expected: "did:plc:other", actual: "did:plc:abc")) { try DIDResolver.parse(documentData: body, expecting: "did:plc:other") } } @Test("Document URLs depend on the DID method") func documentURLs() throws { let resolver = DIDResolver(plcHost: "https://plc.directory") #expect(try resolver.documentURL(for: DID("did:plc:abc")).absoluteString == "https://plc.directory/did:plc:abc") #expect(try resolver.documentURL(for: DID("did:web:catalog.effem.app")).absoluteString == "https://catalog.effem.app/.well-known/did.json") #expect(throws: DIDResolver.ResolutionError.unsupportedMethod("key")) { try resolver.documentURL(for: DID("did:key:z6Mk")) } } }