diff --git a/rust/pact_consumer/src/patterns/special_rules.rs b/rust/pact_consumer/src/patterns/special_rules.rs index 64329669e..13a611f60 100644 --- a/rust/pact_consumer/src/patterns/special_rules.rs +++ b/rust/pact_consumer/src/patterns/special_rules.rs @@ -567,7 +567,7 @@ fn object_matching_test() { MatchingRule::EachKey(MatchingRuleDefinition::new("key1".to_string(), ValueType::String, MatchingRule::Regex("[a-z]{3}[0-9]".to_string()), None)), MatchingRule::EachValue(MatchingRuleDefinition::new("\"value1\"".to_string(), - ValueType::Unknown, MatchingRule::Type, None)) + ValueType::String, MatchingRule::Type, None)) ] }, rules); } @@ -786,7 +786,7 @@ fn each_value_is_pattern() { matchable.extract_matching_rules(DocPath::root(), &mut rules); expect!(rules).to(be_equal_to(matchingrules_list! { "body"; "$" => [ - MatchingRule::EachValue(MatchingRuleDefinition::new("100".to_string(), ValueType::String, + MatchingRule::EachValue(MatchingRuleDefinition::new("\"100\"".to_string(), ValueType::String, MatchingRule::Regex("\\d+".to_string()), None)) ] })); @@ -820,7 +820,7 @@ fn each_value_test() { result.extract_matching_rules(DocPath::root(), &mut rules); expect!(rules).to(be_equal_to(matchingrules_list! { "body"; "$" => [ - MatchingRule::EachValue(MatchingRuleDefinition::new("value1".to_string(), ValueType::Unknown, + MatchingRule::EachValue(MatchingRuleDefinition::new("\"value1\"".to_string(), ValueType::String, MatchingRule::Regex("[a-z]{5}[0-9]".to_string()), None)) ] })); diff --git a/rust/pact_models/src/matchingrules/expressions.rs b/rust/pact_models/src/matchingrules/expressions.rs index 80f39cc66..aae5c1fcb 100644 --- a/rust/pact_models/src/matchingrules/expressions.rs +++ b/rust/pact_models/src/matchingrules/expressions.rs @@ -1676,7 +1676,7 @@ mod test { value_type: ValueType::Unknown, rules: vec![ Either::Left(MatchingRule::EachKey(MatchingRuleDefinition { value: "$.test.one".to_string(), value_type: ValueType::String, rules: vec![Either::Left(MatchingRule::Regex("\\$(\\.\\w+)+".to_string()))], generator: None } )), - Either::Left(MatchingRule::EachValue(MatchingRuleDefinition { value: "".to_string(), value_type: ValueType::Unknown, rules: vec![Either::Left(MatchingRule::Type)], generator: None } )) + Either::Left(MatchingRule::EachValue(MatchingRuleDefinition { value: "".to_string(), value_type: ValueType::String, rules: vec![Either::Left(MatchingRule::Type)], generator: None } )) ], generator: None })); diff --git a/rust/pact_models/src/matchingrules/mod.rs b/rust/pact_models/src/matchingrules/mod.rs index 81b03d687..21c0bed24 100644 --- a/rust/pact_models/src/matchingrules/mod.rs +++ b/rust/pact_models/src/matchingrules/mod.rs @@ -2160,7 +2160,7 @@ mod tests { ] }); expect!(MatchingRule::from_json(&json)).to(be_ok().value( - MatchingRule::EachValue(MatchingRuleDefinition::new("{\"price\": 1.23}".to_string(), + MatchingRule::EachValue(MatchingRuleDefinition::new("{\"price\":1.23}".to_string(), ValueType::Unknown, MatchingRule::Decimal, None))) ); } @@ -2635,4 +2635,22 @@ mod tests { } ) } + + #[test] + #[should_panic] + fn each_value_matching_rule_comparation_test() { + assert_eq!( + matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachValue(MatchingRuleDefinition::new("[\"string value\"]".to_string(), ValueType::Unknown, MatchingRule::Type, None))]}, + matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachValue(MatchingRuleDefinition::new("[\"something else\"]".to_string(), ValueType::Unknown, MatchingRule::Type, None))]} + ) + } + + #[test] + #[should_panic] + fn each_key_matching_rule_comparation_test() { + assert_eq!( + matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachKey(MatchingRuleDefinition::new("a_key".to_string(), ValueType::Unknown, MatchingRule::Type, None))]}, + matchingrules_list!{"body"; "$.array_values" => [MatchingRule::EachKey(MatchingRuleDefinition::new("another_key".to_string(), ValueType::Unknown, MatchingRule::Type, None))]} + ) + } }