Martin Grühn
04/28/2023, 6:26 PMwithRequestMultipartFileUpload to write a consumer test for one of our endpoints. The function is defined as
public withRequestMultipartFileUpload(
req: V3Request,
contentType: string,
file: string,
mimePartName: string
): PactV3 {
[...]
}
, and I was wondering where the mimePartName value is meant to be collected from during the test-execution.
I gather that the the contentType field is taken from the content-type request header, and that the binary file is taken from the form data body.
Where is the mimePartName represented?
The test-implementation for this part looks something like
.withRequestMultipartFileUpload(
{
method: 'POST',
path: endpoint
},
'multipart/form-data',
`${__dirname}/${testFileName}`,
'image/png' // <--- I know that's the mime-type, since the back-end will tell me so
)
During the test-execution, I get the debug-output:
2023-04-28T17:22:00.413534Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing 'multipart/form-data; boundary=R9kK5VpobMo1Lz7p' to 'multipart/form-data; boundary=--------------------------379308910942565113614489' ==> true cascaded=false matcher=Regex("multipart/form-data;(\\s*charset=[^;]*;)?\\s*boundary=.*")
2023-04-28T17:22:00.413554Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [BodyMismatch { path: "$", expected: Some(b"image/png"), actual: None, mismatch: "Expected a MIME part 'image/png' but was missing" }]
The request body of the interaction (as it is implemented by my front-end application) with the actual API-endpoint in the browser looks like shown in the attachments, and there is no mention of the mime-type in the headers as well.
Should the mimePartName parameter of the function be made optional perhaps, as it seems to be in no way mandatory? I could ask my frond-end team to add a header or another value to the form-data, but why should they send an information that has the be gathered/verified by the back-end anyway?
Also, just FYI: I've tried to use the method withRequestBinaryFile instead, since it does not require the mimePartName parameter to be provided, but the test-execution with that one fails due the boundary not being known beforehand, as it is calculated each time anew:
2023-04-28T17:11:50.880036Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Request did not match: Request did not match - HTTP Request ( method: POST, path: /assets, query: None, headers: Some({"Content-Type": ["multipart/form-data; boundary=----515823676253717799984874"]}), body: Present(68987 bytes) ) 0) Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'multipart/form-data; boundary=----xxxx' but was 'multipart/form-data; boundary=--------------------------279702090645891265456368' 1) expected 'multipart/form-data;boundary=----xxxx' body but was 'multipart/form-data;boundary=--------------------------279702090645891265456368'
Thank you for any response on this, highly appreciated! If you would like me to, I could open an issue with the pact-js GitHub repository on this topic.
Hope ya'll have a lovely weekend, MartinMatt (pactflow.io / pact-js / pact-go)
Martin Grühn
05/02/2023, 8:57 AMMartin Grühn
05/09/2023, 11:16 AM