Skip to content
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
27 changes: 23 additions & 4 deletions rust/signed_doc/src/validator/rules/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! `parameters` rule type impl.

use super::doc_ref::referenced_doc_check;
use crate::{
providers::CatalystSignedDocumentProvider, validator::utils::validate_doc_refs,
CatalystSignedDocument, DocType,
Expand Down Expand Up @@ -35,10 +34,30 @@ impl ParametersRule {
{
if let Some(parameters_ref) = doc.doc_meta().parameters() {
let parameters_validator = |ref_doc: CatalystSignedDocument| {
let Ok(ref_doc_type) = ref_doc.doc_type() else {
doc.report().missing_field(
"type",
&format!("{context}, Referenced document must have type field"),
);
return false;
};

// Check that the type matches one of the expected ones
exp_parameters_type.iter().any(|exp_type| {
referenced_doc_check(&ref_doc, exp_type, "parameters", doc.report())
})
if exp_parameters_type
.iter()
.all(|exp_type| ref_doc_type != exp_type)
{
doc.report().invalid_value(
"parameters",
&ref_doc_type.to_string(),
&exp_parameters_type
.iter()
.fold(String::new(), |s, v| format!("{s}, {v}")),
&format!("{context}, Invalid referenced document type"),
);
return false;
}
true
};
return validate_doc_refs(
parameters_ref,
Expand Down
7 changes: 4 additions & 3 deletions rust/signed_doc/tests/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ static COMMENT_TEMPLATE_DOC: LazyLock<CatalystSignedDocument> = LazyLock::new(||
"id": UuidV7::new(),
"ver": UuidV7::new(),
"parameters": {
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
}
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
}
}))
.unwrap()
.with_json_content(&serde_json::json!({
Expand Down Expand Up @@ -167,6 +167,7 @@ async fn test_valid_comment_doc() {
.await
.unwrap();
assert!(is_valid);
assert!(!doc.problem_report().is_problematic());
}

#[tokio::test]
Expand Down
7 changes: 4 additions & 3 deletions rust/signed_doc/tests/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static PROPOSAL_TEMPLATE_DOC: LazyLock<CatalystSignedDocument> = LazyLock::new(|
"id": UuidV7::new(),
"ver": UuidV7::new(),
"parameters": {
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
}
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
},
}))
.unwrap()
.with_json_content(&serde_json::json!({
Expand Down Expand Up @@ -109,6 +109,7 @@ async fn test_valid_proposal_doc() {
.await
.unwrap();
assert!(is_valid);
assert!(!doc.problem_report().is_problematic());
}

#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions rust/signed_doc/tests/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async fn test_valid_submission_action() {
.await
.unwrap();
assert!(is_valid);
assert!(!doc.problem_report().is_problematic());
}

#[tokio::test]
Expand Down
Loading