@@ -35,37 +35,12 @@ impl ParametersRule {
35
35
{
36
36
if let Some ( parameters) = doc. doc_meta ( ) . parameters ( ) {
37
37
let parameters_validator = |replied_doc : CatalystSignedDocument | {
38
- if ! referenced_doc_check (
38
+ referenced_doc_check (
39
39
& replied_doc,
40
40
exp_parameters_type. uuid ( ) ,
41
41
"parameters" ,
42
42
doc. report ( ) ,
43
- ) {
44
- return false ;
45
- }
46
- let Some ( doc_ref) = doc. doc_meta ( ) . doc_ref ( ) else {
47
- doc. report ( )
48
- . missing_field ( "ref" , "Document must have a ref field" ) ;
49
- return false ;
50
- } ;
51
-
52
- let Some ( replied_doc_ref) = replied_doc. doc_meta ( ) . doc_ref ( ) else {
53
- doc. report ( )
54
- . missing_field ( "ref" , "Referenced document must have ref field" ) ;
55
- return false ;
56
- } ;
57
-
58
- if replied_doc_ref. id != doc_ref. id {
59
- doc. report ( ) . invalid_value (
60
- "parameters" ,
61
- doc_ref. id . to_string ( ) . as_str ( ) ,
62
- replied_doc_ref. id . to_string ( ) . as_str ( ) ,
63
- "Invalid referenced document. Document ID should aligned with the replied document." ,
64
- ) ;
65
- return false ;
66
- }
67
-
68
- true
43
+ )
69
44
} ;
70
45
return validate_provided_doc (
71
46
& parameters,
@@ -102,66 +77,47 @@ mod tests {
102
77
use super :: * ;
103
78
use crate :: { providers:: tests:: TestCatalystSignedDocumentProvider , Builder } ;
104
79
105
- #[ allow( clippy:: too_many_lines) ]
106
80
#[ tokio:: test]
107
81
async fn ref_rule_specified_test ( ) {
108
82
let mut provider = TestCatalystSignedDocumentProvider :: default ( ) ;
109
83
110
84
let exp_parameters_type = UuidV4 :: new ( ) ;
111
- let common_ref_id = UuidV7 :: new ( ) ;
112
- let common_ref_ver = UuidV7 :: new ( ) ;
113
85
114
- let valid_replied_doc_id = UuidV7 :: new ( ) ;
115
- let valid_replied_doc_ver = UuidV7 :: new ( ) ;
116
- let another_type_replied_doc_ver = UuidV7 :: new ( ) ;
117
- let another_type_replied_doc_id = UuidV7 :: new ( ) ;
118
- let missing_ref_replied_doc_ver = UuidV7 :: new ( ) ;
119
- let missing_ref_replied_doc_id = UuidV7 :: new ( ) ;
120
- let missing_type_replied_doc_ver = UuidV7 :: new ( ) ;
121
- let missing_type_replied_doc_id = UuidV7 :: new ( ) ;
86
+ let valid_category_doc_id = UuidV7 :: new ( ) ;
87
+ let valid_category_doc_ver = UuidV7 :: new ( ) ;
88
+ let another_type_category_doc_id = UuidV7 :: new ( ) ;
89
+ let another_type_category_doc_ver = UuidV7 :: new ( ) ;
90
+ let missing_type_category_doc_id = UuidV7 :: new ( ) ;
91
+ let missing_type_category_doc_ver = UuidV7 :: new ( ) ;
122
92
123
93
// prepare replied documents
124
94
{
125
95
let ref_doc = Builder :: new ( )
126
96
. with_json_metadata ( serde_json:: json!( {
127
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
128
- "id" : valid_replied_doc_id. to_string( ) ,
129
- "ver" : valid_replied_doc_ver. to_string( ) ,
97
+ "id" : valid_category_doc_id. to_string( ) ,
98
+ "ver" : valid_category_doc_ver. to_string( ) ,
130
99
"type" : exp_parameters_type. to_string( )
131
100
} ) )
132
101
. unwrap ( )
133
102
. build ( ) ;
134
103
provider. add_document ( ref_doc) . unwrap ( ) ;
135
104
136
- // parameters doc with other `type` field
105
+ // reply doc with other `type` field
137
106
let ref_doc = Builder :: new ( )
138
107
. with_json_metadata ( serde_json:: json!( {
139
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
140
- "id" : another_type_replied_doc_id. to_string( ) ,
141
- "ver" : another_type_replied_doc_ver. to_string( ) ,
108
+ "id" : another_type_category_doc_id. to_string( ) ,
109
+ "ver" : another_type_category_doc_ver. to_string( ) ,
142
110
"type" : UuidV4 :: new( ) . to_string( )
143
111
} ) )
144
112
. unwrap ( )
145
113
. build ( ) ;
146
114
provider. add_document ( ref_doc) . unwrap ( ) ;
147
115
148
- // missing `ref` field in the referenced document
149
- let ref_doc = Builder :: new ( )
150
- . with_json_metadata ( serde_json:: json!( {
151
- "id" : missing_ref_replied_doc_id. to_string( ) ,
152
- "ver" : missing_ref_replied_doc_ver. to_string( ) ,
153
- "type" : exp_parameters_type. to_string( )
154
- } ) )
155
- . unwrap ( )
156
- . build ( ) ;
157
- provider. add_document ( ref_doc) . unwrap ( ) ;
158
-
159
116
// missing `type` field in the referenced document
160
117
let ref_doc = Builder :: new ( )
161
118
. with_json_metadata ( serde_json:: json!( {
162
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
163
- "id" : missing_type_replied_doc_id. to_string( ) ,
164
- "ver" : missing_type_replied_doc_ver. to_string( ) ,
119
+ "id" : missing_type_category_doc_id. to_string( ) ,
120
+ "ver" : missing_type_category_doc_ver. to_string( ) ,
165
121
} ) )
166
122
. unwrap ( )
167
123
. build ( ) ;
@@ -175,8 +131,7 @@ mod tests {
175
131
} ;
176
132
let doc = Builder :: new ( )
177
133
. with_json_metadata ( serde_json:: json!( {
178
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
179
- "parameters" : { "id" : valid_replied_doc_id. to_string( ) , "ver" : valid_replied_doc_ver. to_string( ) }
134
+ "parameters" : { "id" : valid_category_doc_id. to_string( ) , "ver" : valid_category_doc_ver }
180
135
} ) )
181
136
. unwrap ( )
182
137
. build ( ) ;
@@ -195,38 +150,13 @@ mod tests {
195
150
exp_parameters_type,
196
151
optional : false ,
197
152
} ;
198
- let doc = Builder :: new ( )
199
- . with_json_metadata ( serde_json:: json!( {
200
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
201
- } ) )
202
- . unwrap ( )
203
- . build ( ) ;
204
- assert ! ( !rule. check( & doc, & provider) . await . unwrap( ) ) ;
205
-
206
- // missing `ref` field
207
- let doc = Builder :: new ( )
208
- . with_json_metadata ( serde_json:: json!( {
209
- "parameters" : { "id" : valid_replied_doc_id. to_string( ) , "ver" : valid_replied_doc_ver. to_string( ) }
210
- } ) )
211
- . unwrap ( )
212
- . build ( ) ;
153
+ let doc = Builder :: new ( ) . build ( ) ;
213
154
assert ! ( !rule. check( & doc, & provider) . await . unwrap( ) ) ;
214
155
215
156
// reference to the document with another `type` field
216
157
let doc = Builder :: new ( )
217
158
. with_json_metadata ( serde_json:: json!( {
218
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
219
- "parameters" : { "id" : another_type_replied_doc_id. to_string( ) , "ver" : another_type_replied_doc_ver. to_string( ) }
220
- } ) )
221
- . unwrap ( )
222
- . build ( ) ;
223
- assert ! ( !rule. check( & doc, & provider) . await . unwrap( ) ) ;
224
-
225
- // missing `ref` field in the referenced document
226
- let doc = Builder :: new ( )
227
- . with_json_metadata ( serde_json:: json!( {
228
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
229
- "parameters" : { "id" : missing_ref_replied_doc_id. to_string( ) , "ver" : missing_type_replied_doc_ver. to_string( ) }
159
+ "parameters" : { "id" : another_type_category_doc_id. to_string( ) , "ver" : another_type_category_doc_ver. to_string( ) }
230
160
} ) )
231
161
. unwrap ( )
232
162
. build ( ) ;
@@ -235,18 +165,7 @@ mod tests {
235
165
// missing `type` field in the referenced document
236
166
let doc = Builder :: new ( )
237
167
. with_json_metadata ( serde_json:: json!( {
238
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
239
- "parameters" : { "id" : missing_type_replied_doc_id. to_string( ) , "ver" : missing_type_replied_doc_ver. to_string( ) }
240
- } ) )
241
- . unwrap ( )
242
- . build ( ) ;
243
- assert ! ( !rule. check( & doc, & provider) . await . unwrap( ) ) ;
244
-
245
- // `ref` field does not align with the referenced document
246
- let doc = Builder :: new ( )
247
- . with_json_metadata ( serde_json:: json!( {
248
- "ref" : { "id" : UuidV7 :: new( ) . to_string( ) , "ver" : UuidV7 :: new( ) . to_string( ) } ,
249
- "parameters" : { "id" : valid_replied_doc_id. to_string( ) , "ver" : valid_replied_doc_ver. to_string( ) }
168
+ "parameters" : { "id" : missing_type_category_doc_id. to_string( ) , "ver" : missing_type_category_doc_ver. to_string( ) }
250
169
} ) )
251
170
. unwrap ( )
252
171
. build ( ) ;
@@ -255,7 +174,6 @@ mod tests {
255
174
// cannot find a referenced document
256
175
let doc = Builder :: new ( )
257
176
. with_json_metadata ( serde_json:: json!( {
258
- "ref" : { "id" : common_ref_id. to_string( ) , "ver" : common_ref_ver. to_string( ) } ,
259
177
"parameters" : { "id" : UuidV7 :: new( ) . to_string( ) , "ver" : UuidV7 :: new( ) . to_string( ) }
260
178
} ) )
261
179
. unwrap ( )
0 commit comments