From ca34b29f85cf162af41de4dc54a5cb11ff4b592c Mon Sep 17 00:00:00 2001 From: Alex Hsieh Date: Thu, 2 May 2024 13:16:43 +0800 Subject: [PATCH] add universal resolver register test; fix did resource test error --- Tests/Web5Tests/Dids/DIDResourceTests.swift | 2 +- .../Dids/DIDUniversalResolverTests.swift | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Tests/Web5Tests/Dids/DIDResourceTests.swift b/Tests/Web5Tests/Dids/DIDResourceTests.swift index 8673444..0e3168a 100644 --- a/Tests/Web5Tests/Dids/DIDResourceTests.swift +++ b/Tests/Web5Tests/Dids/DIDResourceTests.swift @@ -22,7 +22,7 @@ final class DIDResourceTests: XCTestCase { let did = try! DIDJWK.create() let didDocument = await DIDUniversalResolver.DIDResolver().resolve(didURI: did.uri).didDocument let resource = DIDResource.didDocument(didDocument!) - let encoded = try! JSONEncoder().encode(didDocument) + let encoded = try! JSONEncoder().encode(resource) let decoded = try! JSONDecoder().decode(DIDResource.self, from: encoded) XCTAssertEqual(decoded, resource) } diff --git a/Tests/Web5Tests/Dids/DIDUniversalResolverTests.swift b/Tests/Web5Tests/Dids/DIDUniversalResolverTests.swift index e676f06..318aa86 100644 --- a/Tests/Web5Tests/Dids/DIDUniversalResolverTests.swift +++ b/Tests/Web5Tests/Dids/DIDUniversalResolverTests.swift @@ -90,4 +90,19 @@ final class DIDUniversalResolverTests: XCTestCase { XCTAssertNotNil(result.dereferencingMetadata.error) XCTAssertEqual(result.dereferencingMetadata.error, DID.Error.notFound.localizedDescription) } + + func testRegisterResolver() async { + + struct MockResolver: DIDMethodResolver { + public let methodName = "mock" + public func resolve(didURI: String) async -> DIDResolutionResult { + let metaData = DIDResolutionResult.Metadata(contentType: "this is mock resolver") + return DIDResolutionResult(didResolutionMetadata: metaData) + } + } + + DIDUniversalResolver.register(resolver: MockResolver()) + let result = await universalResolver.resolve(didURI: "did:mock:abc123") + XCTAssertEqual(result.didResolutionMetadata.contentType, "this is mock resolver") + } } \ No newline at end of file