Skip to content

Commit

Permalink
chore: Add test with POST with body and no content type #386
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Feb 17, 2024
1 parent c4e5ffe commit 208eb75
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rust/pact_verifier/tests/no-content-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"consumer": { "name": "thing" },
"provider": { "name": "other-thing" },
"interactions": [{
"description": "a request to the other thing",
"request": {
"method": "post",
"path": "/endpoint",
"body": {
"this": "field"
}
},
"response": {
"status": 200
}
}],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
46 changes: 46 additions & 0 deletions rust/pact_verifier/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,49 @@ async fn broker_validation_errors_should_be_shown_to_the_user() {
let message_str = message.to_string();
expect!(message_str.contains("consumerVersionSelectors: cannot specify the fields branch/latest with the field deployedOrReleased (at index 0)")).to(be_true());
}

#[test_log::test(tokio::test)]
async fn verify_pact_with_body_but_no_content_type() {
let server = PactBuilder::new_v4("no content-type", "no content-type")
.interaction("request with no content-type", "", |mut i| {
i.test_name("verify_pact_with_body_but_no_content_type");
i.request.method("POST");
i.request.path("/endpoint");
i.request.body(r#"{ "this": "field" }"#);

i.response.ok();
i
})
.start_mock_server(None);

#[allow(deprecated)]
let provider = ProviderInfo {
name: "no content-type".to_string(),
host: "127.0.0.1".to_string(),
port: server.url().port(),
transports: vec![ ProviderTransport {
transport: "HTTP".to_string(),
port: server.url().port(),
path: None,
scheme: Some("http".to_string())
} ],
.. ProviderInfo::default()
};

let pact_file = fixture_path("no-content-type.json");
let pact = read_pact(pact_file.as_path()).unwrap();
let options: VerificationOptions<NullRequestFilterExecutor> = VerificationOptions::default();
let provider_states = Arc::new(DummyProviderStateExecutor{});

let result = verify_pact_internal(
&provider,
&FilterInfo::None,
pact,
&options,
&provider_states,
false,
Duration::default()
).await;

expect!(result.unwrap().results.get(0).unwrap().result.as_ref()).to(be_ok());
}

0 comments on commit 208eb75

Please sign in to comment.