Hello party people. :upside_down_face: Big fan, t...
# pact-js
m
Hello party people. 🙃 Big fan, thank you for everything you do. I wanted to gather some feedback on a problem I've ran into a while ago. I'm using pact-js and I'm trying to use the method
withRequestMultipartFileUpload
to write a consumer test for one of our endpoints. The function is defined as
Copy code
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
Copy code
.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:
Copy code
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:
Copy code
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, Martin
❤️ 1
m
Hi Martin! thank you both for the kind words and detailed post. I’ll take a look at this tomorrow 👍
m
Thank you!
Hi @Matt (pactflow.io / pact-js / pact-go). Did you have a chance to look into this behavior by chance? My front-end devs are waiting on an update from my side. Thanks!