Skip to content

Commit f65ed33

Browse files
authored
feat(rust/signed-doc): Fixing ParametersRule validation (#445)
* fix issue with adding problem report when everything is fine * fix * fix * wip * wip
1 parent 70c611c commit f65ed33

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

rust/signed_doc/src/validator/rules/parameters.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! `parameters` rule type impl.
22
3-
use super::doc_ref::referenced_doc_check;
43
use crate::{
54
providers::CatalystSignedDocumentProvider, validator::utils::validate_doc_refs,
65
CatalystSignedDocument, DocType,
@@ -35,10 +34,30 @@ impl ParametersRule {
3534
{
3635
if let Some(parameters_ref) = doc.doc_meta().parameters() {
3736
let parameters_validator = |ref_doc: CatalystSignedDocument| {
37+
let Ok(ref_doc_type) = ref_doc.doc_type() else {
38+
doc.report().missing_field(
39+
"type",
40+
&format!("{context}, Referenced document must have type field"),
41+
);
42+
return false;
43+
};
44+
3845
// Check that the type matches one of the expected ones
39-
exp_parameters_type.iter().any(|exp_type| {
40-
referenced_doc_check(&ref_doc, exp_type, "parameters", doc.report())
41-
})
46+
if exp_parameters_type
47+
.iter()
48+
.all(|exp_type| ref_doc_type != exp_type)
49+
{
50+
doc.report().invalid_value(
51+
"parameters",
52+
&ref_doc_type.to_string(),
53+
&exp_parameters_type
54+
.iter()
55+
.fold(String::new(), |s, v| format!("{s}, {v}")),
56+
&format!("{context}, Invalid referenced document type"),
57+
);
58+
return false;
59+
}
60+
true
4261
};
4362
return validate_doc_refs(
4463
parameters_ref,

rust/signed_doc/tests/comment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ static COMMENT_TEMPLATE_DOC: LazyLock<CatalystSignedDocument> = LazyLock::new(||
5757
"id": UuidV7::new(),
5858
"ver": UuidV7::new(),
5959
"parameters": {
60-
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
61-
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
62-
}
60+
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
61+
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
62+
}
6363
}))
6464
.unwrap()
6565
.with_json_content(&serde_json::json!({
@@ -167,6 +167,7 @@ async fn test_valid_comment_doc() {
167167
.await
168168
.unwrap();
169169
assert!(is_valid);
170+
assert!(!doc.problem_report().is_problematic());
170171
}
171172

172173
#[tokio::test]

rust/signed_doc/tests/proposal.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static PROPOSAL_TEMPLATE_DOC: LazyLock<CatalystSignedDocument> = LazyLock::new(|
4141
"id": UuidV7::new(),
4242
"ver": UuidV7::new(),
4343
"parameters": {
44-
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
45-
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
46-
}
44+
"id": DUMMY_BRAND_DOC.doc_id().unwrap(),
45+
"ver": DUMMY_BRAND_DOC.doc_ver().unwrap(),
46+
},
4747
}))
4848
.unwrap()
4949
.with_json_content(&serde_json::json!({
@@ -109,6 +109,7 @@ async fn test_valid_proposal_doc() {
109109
.await
110110
.unwrap();
111111
assert!(is_valid);
112+
assert!(!doc.problem_report().is_problematic());
112113
}
113114

114115
#[tokio::test]

rust/signed_doc/tests/submission.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ async fn test_valid_submission_action() {
103103
.await
104104
.unwrap();
105105
assert!(is_valid);
106+
assert!(!doc.problem_report().is_problematic());
106107
}
107108

108109
#[tokio::test]

0 commit comments

Comments
 (0)