Skip to content

Commit

Permalink
chore: add a test for generators on query parameters with square brac…
Browse files Browse the repository at this point in the history
…kets #359
  • Loading branch information
rholshausen committed Jan 19, 2024
1 parent 9d60c8b commit ce42152
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions rust/pact_matching/src/generator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ async fn applies_header_generator_for_headers_to_the_copy_of_the_request() {
#[tokio::test]
async fn applies_query_generator_for_query_parameters_to_the_copy_of_the_request() {
let request = HttpRequest { query: Some(hashmap!{
s!("A") => vec![ s!("a") ],
s!("B") => vec![ s!("b") ]
"A".to_string() => vec![ "a".to_string() ],
"B".to_string() => vec![ "b".to_string() ]
}), generators: generators! {
"QUERY" => {
"A" => Generator::Uuid(None)
Expand All @@ -88,6 +88,32 @@ async fn applies_query_generator_for_query_parameters_to_the_copy_of_the_request
expect!(query_val).to_not(be_equal_to("a"));
}

#[test_log::test(tokio::test)]
async fn applies_provider_state_generator_for_query_parameters_with_square_brackets() {
let request = HttpRequest {
query: Some(hashmap!{
"A".to_string() => vec![ "a".to_string() ],
"q[]".to_string() => vec![ "q1".to_string(), "q2".to_string() ]
}),
generators: generators! {
"QUERY" => {
"A" => Generator::ProviderStateGenerator("exp1".to_string(), None),
"$['q[]']" => Generator::ProviderStateGenerator("${exp2}".to_string(), None)
}
}, .. HttpRequest::default()
};
let context = hashmap! {
"exp1" => json!("1234"),
"exp2" => json!("5678")
};
let result = generate_request(&request, &GeneratorTestMode::Provider, &context).await;
let query = result.query.unwrap();
let a_val = query.get("A").unwrap();
expect!(a_val).to(be_equal_to(&vec!["1234".to_string()]));
let q_val = query.get("q[]").unwrap();
expect!(q_val).to(be_equal_to(&vec!["5678".to_string(), "5678".to_string()]));
}

#[tokio::test]
async fn applies_body_generator_to_the_copy_of_the_request() {
let request = HttpRequest { body: OptionalBody::Present("{\"a\": 100, \"b\": \"B\"}".into(), None, None),
Expand Down

0 comments on commit ce42152

Please sign in to comment.