Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default presentation preview message family #590

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
format!("No 'value' field in cred_value: {:?}", cred_value),
))?;
credential_preview =
credential_preview.add_value(&key.to_string(), &value.to_string(), MimeType::Plain);
credential_preview.add_value(
&key.as_str()
.ok_or(
VcxError::from_msg(
VcxErrorKind::InvalidOption,
"Credential value names are currently only allowed to be strings",
)
)?,
&value.as_str()
.ok_or(
VcxError::from_msg(
VcxErrorKind::InvalidOption,
"Credential values are currently only allowed to be strings",
)
)?,
MimeType::Plain
);
}
}
serde_json::Value::Object(values_map) => {
Expand Down Expand Up @@ -343,25 +359,36 @@ pub mod unit_tests {

#[tokio::test]
async fn test_build_credential_preview() {
fn verify_preview(preview: CredentialPreviewData) {
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");
}

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");
verify_preview(preview);

let input = json!([
{"name":"name", "value": "Alice"},
{"name": "age", "value": "123"}
]).to_string();
let preview = _build_credential_preview(&input).unwrap();
verify_preview(preview);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion messages/src/proof_presentation/presentation_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Predicate {
}

fn default_presentation_preview_type() -> MessageType {
MessageType::build(MessageFamilies::CredentialIssuance, "presentation-preview")
MessageType::build(MessageFamilies::PresentProof, "presentation-preview")
}

impl PresentationProposal {
Expand Down