Quinn
03/01/2022, 10:18 PMExpected body with content type application/json but was image/jpeg
. Can anyone please help?Quinn
03/01/2022, 10:18 PMconst { pactWith } = require("jest-pact/v3");
const { MatchersV3 } = require("@pact-foundation/pact/v3");
const mockPactServerClient = require("../../utility/mockPactServer");
const fs = require("fs");
const { string } = MatchersV3;
pactWith(
{
consumer: "bulk-upload",
provider: "upload-provider",
logLevel: 'INFO',
port: 8081,
},
(interaction) => {
const fileBody = Buffer.from(fs.readFileSync("pikachu.png")).toString("base64");
interaction("initiateUpload", ({provider, execute}) => {
beforeEach(() =>
provider
.uponReceiving("Initiate Upload")
.withRequest({
method: "PUT",
path: '/bar/foo',
headers: {
Authorization: string("headerbar"),
Accept: 'image/jpeg',
'Content-Type': 'image/jpeg',
},
body: fileBody
})
.willRespondWith({
status: 201
})
);
execute("Content-type bug test", () => {
return mockPactServerClient.put(
'/bar/foo',
fileBody,
{
headers: {
Authorization: "Bearer Auth",
Accept: 'image/jpeg',
"Content-Type": "image/jpeg",
},
}
);
});
}
)
}
);
Quinn
03/01/2022, 10:19 PM"image/jpeg"
everywhere, but it's still looking for application/json
?Quinn
03/01/2022, 10:29 PMQuinn
03/01/2022, 10:29 PM● Pact between bulk-upload and upload-provider › with 30000 ms timeout for Pact › initiateUpload › Content-type bug test
Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was incorrect:
PUT /bar/foo
1.0 Expected body with content type application/json but was image/jpeg
Matt (pactflow.io / pact-js / pact-go)
contentType
property on the request and response bodies. That is part of the API I’m still looking at addressing.
We’re in an awkward state where I’d like to continue support the JSON-like setup above, but it means certain options aren’t forced to be set. I’d prefer a type-state builder style API, but that won’t play nice with Jest Pact etc.Quinn
03/02/2022, 6:05 PMQuinn
03/02/2022, 6:05 PMQuinn
03/02/2022, 6:08 PMapplication/foo.bar.bulk-transfer+json
. Interestingly, if I don't use the "+" and change it to a "-", It will match. Something may be going on with matching "+" signs? A similar contentType is used in my company that I cannot change. Do you have any ideas on this? @Matt (pactflow.io / pact-js / pact-go)Quinn
03/02/2022, 6:09 PMconst { pactWith } = require("jest-pact/v3");
const { MatchersV3 } = require("@pact-foundation/pact/v3");
const mockPactServerClient = require("../../utility/mockPactServer");
const { string } = MatchersV3;
pactWith(
{
consumer: "bulk-upload",
provider: "upload-provider",
logLevel: "INFO",
port: 8081,
},
(interaction) => {
interaction("initiateUpload", ({ provider, execute }) => {
beforeEach(() =>
provider
.given("An experiance user")
//These can share a state handler. However because we don't actually need to do anything, it's not needed in this case.
.uponReceiving("A disallowed but allowed asset name")
.withRequest({
method: "POST",
path: "/bar/foo",
headers: {
Authorization: string("headerbar"),
},
body: {
"dc:format": "image/jpeg",
},
contentType: 'application/foo.bar.bulk-transfer+json',
})
.willRespondWith({
status: 200,
headers: {},
body: {
"dc:format": string("image/jpeg"),
},
contentType: 'application/foo.bar.bulk-transfer+json',
})
);
execute("Create Disallowed Asset", () => {
return <http://mockPactServerClient.post|mockPactServerClient.post>(
"/bar/foo",
{
"dc:format": "image/jpeg",
},
{
headers: {
Authorization: "Bearer Auth",
"Content-Type": 'application/foo.bar.bulk-transfer+json',
},
}
);
});
});
}
);
Quinn
03/02/2022, 9:52 PMQuinn
03/02/2022, 9:52 PMQuinn
03/02/2022, 9:53 PM"Content-Type": regex(
/application\/vfoo.bar.bulk-transfer\+json/, "application/foo.bar.bulk-transfer+json"),
This is what the regex will look like, and it will match on the incoming header from a requestQuinn
03/02/2022, 9:54 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
, if I don’t use the “+” and change it to a “-”, It will match. Something may be going on with matching “+” signs?smells of escaping or something doesn’t it.
Matt (pactflow.io / pact-js / pact-go)