Closed krishnaraghavendra closed 2 years ago
This is not a very helpful bug report in the current form. Can you please create a minimal example we can use to reproduce the problem?
For example, without seeing your test setup and the actual call being made we don't have much to go on.
`let client: BaseAPI; beforeAll(() => { const conf = new Configuration({ basePath: mockProvider.mockService.baseUrl, });
client = new BaseAPI(conf);
});
describe('create test', () => {
it('with sucessfull response', async () => {
interaction:{
state: test,
uponReceiving: test,
withRequest: {
method: POST,
path: /test,
body:[
{
test1: test1-123,
test2:[
ns1.test2,
ns2.test2
],
test3: 10.0.0.1,
test4: 10.0.0.1/27
}
]
},
willRespondWith: {
status: 201,
headers: {
Content-Type: application/json; charset=utf-8
},
body: {
test: 1,
teststatus: ACCEPTED
}
}
}
await mockProvider.addInteraction(interaction);
// eslint-disable-next-line max-len
const { test } = (await client.create(1, interaction.withRequest.body)).data;
console.log(test);
});`
I think your code snippet is broken. For example, the body
section has unescaped property values which doesn't appear to be valid JSON or JS - did you write this by hand? If not, this would be worth looking into first.
Also, you removed the section of the bug report template that requests log information. I'd like both the full terminal output at DEBUG
level and the pact log file (see https://github.com/pact-foundation/pact-js#troubleshooting--faqs for how to do this). This will help us investigate where it is failing.
Lastly, this is still not reproducable. Depending on the above and where the failure is in the lifecycle of things (hopefully it's at mockProvider.addInteraction(...)
), we will likely need to know what client.create(...) actually does
.
Interaction is
export const interaction = {
state: 'test',
uponReceiving: 'test',
withRequest: {
method: HTTPMethod.POST,
path: '/test',
body:[
{
test1: 'test1-123',
test2:[
'ns1.test2',
'ns2.test2'
],
test3: '10.0.0.1',
test4: '10.0.0.1/27'
}
]
},
willRespondWith: {
status: 201,
headers: {
Content-Type: 'application/json; charset=utf-8'
},
body: {
test: '1',
teststatus: 'ACCEPTED'
}
}
}
consumer test is
pactWith({
consumer: 'test-sdk',
provider: 'test',
log: process.env.output_dir
? resolve(process.env.output_dir, 'consumer-pact-logs') : 'outputs/consumer-pact-logs',
dir: process.env.output_dir ? resolve(process.env.output_dir, 'pacts') : 'outputs/pacts',
}, (mockProvider) => {
describe(`Consumer tests for ${pkgJson.name} using latest ${pkgJson.name}-sdk`, () => {
let client: BaseAPI;
beforeAll(() => {
const conf = new Configuration({
basePath: mockProvider.mockService.baseUrl,
});
client = new BaseAPI(conf);
});
describe('create test', () => {
it('with sucessfull response', async () => {
await mockProvider.addInteraction(interaction);
// eslint-disable-next-line max-len
const { test } = (await client.create(1, interaction.withRequest.body)).data;
console.log(test);
});
});
});
});
Thanks, this helps a little. For future reference,you should use the triple backtick (or use the code block button) from the editor to properly format your code. i've done that now.
I still need your logs, and I still need to know exactly what your API client is doing.
It looks like the body of the request has double quotes around it.
Expected behaviour
Make a request successfully
Actual behaviour
Steps to reproduce
I am using jest pact version - 0.9.1, when trying to make a post request , i get the above error. I am making post request using open api generated sdk. My post requests accepts an array of objects as input