Skip to content

Commit

Permalink
add universal resolver register test; fix did resource test error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHsieh committed May 2, 2024
1 parent 8e84ef7 commit ca34b29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tests/Web5Tests/Dids/DIDResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/Web5Tests/Dids/DIDUniversalResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit ca34b29

Please sign in to comment.