Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Anderson committed Nov 14, 2022
1 parent 1cb8d41 commit 8cf8988
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions identity_did/src/document/core_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,11 +1418,13 @@ mod tests {
}

#[test]
fn insert_method_other_did_same_fragment() {
fn test_behaviour_duplicate_fragment_different_dids() {
let mut document: CoreDocument = document();
// insert a method and a service into the document with the same fragment, but with DIDs different from the
// document's.
let fragment = "#same-fragment";
let method_other_did = method(&"did:other:123".parse().unwrap(), fragment);
let service: Service = ServiceBuilder::default()
let mut service: Service = ServiceBuilder::default()
.id(DIDUrl::parse("did:other:456").unwrap().join(fragment).unwrap())
.type_("testService")
.service_endpoint(Url::parse("http://example.com").unwrap())
Expand All @@ -1431,7 +1433,7 @@ mod tests {
assert!(document
.insert_method(method_other_did, MethodScope::VerificationMethod)
.is_ok());
assert!(document.insert_service(service).is_ok());
assert!(document.insert_service(service.clone()).is_ok());

let scopes = [
MethodScope::VerificationMethod,
Expand All @@ -1443,11 +1445,20 @@ mod tests {
];

for scope in scopes {
// insert a method with the same fragment, but using the document's DID this time.
let mut document_clone = document.clone();
let new_method = method(document.id(), fragment);
let result = document.insert_method(new_method, scope);
dbg!(&result);
let result = document_clone.insert_method(new_method.clone(), scope);
assert!(result.is_ok());
// now query for this method by fragment
assert_eq!(Some(&new_method), document_clone.resolve_method(fragment, Some(scope)));
}

// Now finally we insert another service with the same fragment, but using the document's DID.
assert!(service.set_id(document.id().to_url().join(fragment).unwrap()).is_ok());
assert!(document.insert_service(service.clone()).is_ok());
// Query for this service
assert_eq!(Some(&service), document.resolve_service(fragment));
}

#[test]
Expand Down

0 comments on commit 8cf8988

Please sign in to comment.