Open spawluk-zartis opened 1 year ago
Thanks for the repro.
I also get the x-tex
issue on my MacOSX also. It depends on the mime database available on the OS.
1.0 $.file: MIME part 'file': Expected binary contents to have content type 'application/pdf' but detected contents was 'text/x-tex'
@uglyog FYI.
I think in this case, you're best falling back to not using that method, and using something like this instead:
it("upload data and return 201", () => {
provider
.uponReceiving("a request to upload pdf")
.withRequest({
method: "POST",
path: "/api/upload",
headers: {
"Content-Type": MatchersV3.regex("multipart\/form-data; boundary=.*", "multipart/form-data; boundary=axios-1.3.4-boundary-Py9nQHSit6xdTOTPzJ2U6vH54"),
"Content-Length": `981`, // Ideally this is also set, you could probably get it from the FormData object
},
body: "--boundary......" // see pseudo-code here, albeit it's probably not strictly that valuable: https://github.com/pact-foundation/pact-net/issues/410#issuecomment-1457853792
})
.willRespondWith({
status: 204
});
Latest pact versions.
Same with image/png file:
BodyMismatch { path: "$.file['content-type']", expected: Some(b"image/png"), actual: Some(b"application/octet-stream"), mismatch: "MIME part 'file': header 'content-type': Expected 'application/octet-stream' to be equal to 'image/png'" }]
interaction('A request for POST an App', ({ provider, execute }) => { const PNG_FILE_PATH = path.join(__dirname, "archie.png"); console.log(__dirname ) beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientModule], providers: [AppsHttpService], }); provider .given('Apps API available') .uponReceiving('a request to create an app through AppsHttpService') .withRequestMultipartFileUpload( { method: "POST", path:
/apps, body: {"title":"test.nl","thumbnail_url":"archie.png","image_url":"archie.png","url":{"ios":"test.nl","android":"test.nl","web":"test.nl"}} }, "application/octet-stream", PNG_FILE_PATH, "file" ) .willRespondWith({ status: 200, }) } );
When I change the "application/octet-stream" to "image/png", I got the error other way around:
BodyTypeMismatch { expected: "image/png", actual: "application/octet-stream", mismatch: "MIME part 'file': Expected a body of 'image/png' but the actual content type was 'application/octet-stream'"
@mefellows Can this please be fixed? :)
Thanks for contributing to the discussion, there is no need to ask for it to be fixed though. Clearly there is a bug that needs fixing.
You're welcome to help fix it, or use the suggested workaround. We'll get to a fix when we can.
@mefellows I did some extra testing, but this is a pact-js-core issue in my opinion. If I change this test with a .png image file, the same error occures.
Software versions
Issue Checklist
Please confirm the following:
Expected behaviour
When testing
multipart/form-data
upload, PDF file should be detected asapplication/pdf
orapplication/octet-stream
Actual behaviour
The uploaded PDF file is detected as
text/plain
.Moreover on Azure DevOps agent running Ubuntu, the same file is detected as
text/x-tex
I'm not 100% sure but I think it is related to mime type detection logic here
Steps to reproduce
Clone https://github.com/spawluk-zartis/pact-multipart-form-data-upload
Relevant log files