Skip to content

Commit

Permalink
Modify tests for unmapped types (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Jul 10, 2024
1 parent 0e87bfe commit 95d0676
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
53 changes: 53 additions & 0 deletions crates/claims/crates/vc/src/syntax/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,56 @@ where
json.expand_with(ld, loader).await
}
}

#[cfg(test)]
mod tests {
use ssi_json_ld::{json_ld, ContextLoader, Expandable};

use super::*;

#[async_std::test]
async fn reject_undefined_type_v2() {
let input: AnyJsonCredential = serde_json::from_value(serde_json::json!({
"@context": [
"https://www.w3.org/ns/credentials/v2",
{ "@vocab": null }
],
"type": [
"VerifiableCredential",
"ExampleTestCredential"
],
"issuer": "did:example:issuer",
"credentialSubject": {
"id": "did:example:subject"
}
}))
.unwrap();
match input.expand(&ContextLoader::default()).await.unwrap_err() {
JsonLdError::Expansion(json_ld::expansion::Error::InvalidTypeValue) => (),
e => panic!("{:?}", e),
}
}

#[async_std::test]
async fn reject_undefined_type_v1() {
let input: AnyJsonCredential = serde_json::from_value(serde_json::json!({
"@context": [
"https://www.w3.org/2018/credentials/v1",
{ "@vocab": null }
],
"type": [
"VerifiableCredential",
"ExampleTestCredential"
],
"issuer": "did:example:issuer",
"credentialSubject": {
"id": "did:example:subject"
}
}))
.unwrap();
match input.expand(&ContextLoader::default()).await.unwrap_err() {
JsonLdError::Expansion(json_ld::expansion::Error::InvalidTypeValue) => (),
e => panic!("{:?}", e),
}
}
}
15 changes: 10 additions & 5 deletions crates/claims/crates/vc/src/v1/syntax/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ where

#[cfg(test)]
mod tests {
use ssi_json_ld::{CompactJsonLd, ContextLoader, Expandable};
use ssi_json_ld::{json_ld, ContextLoader, Expandable};

use super::*;

#[async_std::test]
async fn reject_undefined_type() {
let input = CompactJsonLd(json_syntax::json!({
let input: JsonCredential = serde_json::from_value(serde_json::json!({
"@context": [
"https://www.w3.org/2018/credentials/v1",
{ "@vocab": null }
Expand All @@ -286,8 +288,11 @@ mod tests {
"credentialSubject": {
"id": "did:example:subject"
}
}));

assert!(input.expand(&ContextLoader::default()).await.is_err());
}))
.unwrap();
match input.expand(&ContextLoader::default()).await.unwrap_err() {
JsonLdError::Expansion(json_ld::expansion::Error::InvalidTypeValue) => (),
e => panic!("{:?}", e),
}
}
}
15 changes: 10 additions & 5 deletions crates/claims/crates/vc/src/v2/syntax/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ where

#[cfg(test)]
mod tests {
use ssi_json_ld::{CompactJsonLd, ContextLoader, Expandable};
use ssi_json_ld::{json_ld, ContextLoader, Expandable};

use super::*;

#[async_std::test]
async fn reject_undefined_type() {
let input = CompactJsonLd(json_syntax::json!({
let input: JsonCredential = serde_json::from_value(serde_json::json!({
"@context": [
"https://www.w3.org/ns/credentials/v2",
{ "@vocab": null }
Expand All @@ -264,8 +266,11 @@ mod tests {
"credentialSubject": {
"id": "did:example:subject"
}
}));

assert!(input.expand(&ContextLoader::default()).await.is_err());
}))
.unwrap();
match input.expand(&ContextLoader::default()).await.unwrap_err() {
JsonLdError::Expansion(json_ld::expansion::Error::InvalidTypeValue) => (),
e => panic!("{:?}", e),
}
}
}

0 comments on commit 95d0676

Please sign in to comment.