Skip to content

Commit

Permalink
Add test, remove extra quotes serialized into credential preview attr…
Browse files Browse the repository at this point in the history
…ibute values (#503)

Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas authored Jun 30, 2022
1 parent 47d5813 commit e87eb37
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub struct IssuerConfig {
}

fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPreviewData> {
trace!("Issuer::_build_credential_preview >>> credential_json: {:?}", credential_json);

trace!("Issuer::_build_credential_preview >>> credential_json: {:?}", secret!(credential_json));
let cred_values: serde_json::Value = serde_json::from_str(credential_json)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Can't deserialize credential preview json. credential_json: {}, error: {:?}", credential_json, err)))?;

Expand All @@ -48,7 +47,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
let (key, value) = item;
credential_preview = credential_preview.add_value(
key,
&value.to_string(),
value.as_str().ok_or_else(|| VcxError::from_msg(VcxErrorKind::InvalidOption, "Credential values are currently only allowed to be strings"))?,
MimeType::Plain,
);
}
Expand Down Expand Up @@ -242,6 +241,20 @@ pub mod test {
}
}

#[tokio::test]
#[cfg(feature = "general_test")]
async fn test_build_credential_preview() {
let _setup = SetupMocks::init();
let input = json!({"name":"Alice","age":"123"}).to_string();
let preview = _build_credential_preview(&input).unwrap();
let value_name = preview.attributes.clone().into_iter().find(|x| x.name == "name").unwrap();
let value_age = preview.attributes.clone().into_iter().find(|x| x.name == "age").unwrap();
assert_eq!(value_name.name, "name");
assert_eq!(value_name.value, "Alice");
assert_eq!(value_age.name, "age");
assert_eq!(value_age.value, "123");
}

#[tokio::test]
#[cfg(feature = "general_test")]
async fn test_cant_revoke_without_revocation_details() {
Expand Down

0 comments on commit e87eb37

Please sign in to comment.