pactumjs / pactum

REST API Testing Tool for all levels in a Test Pyramid
https://pactumjs.github.io
MIT License
538 stars 52 forks source link

Withmultipart_formdata is not accepting json payload #380

Open JyotiPMallick opened 1 week ago

JyotiPMallick commented 1 week ago

Describe the bug

I am trying to make a post call with accept multipart form data, and one of its parameters (this one is mandatory) is only accepting JSON payload. But the spec handler is unable to identify the JSON data.

To Reproduce Steps to reproduce the behavior:

My spec handler :

image

My JSON payload which contains some synthetic data produced through function,

image

Now while running I am getting the below error,

image

Same thing from the browser

image

Expected behavior It should add the details.

Software (please complete the following information):

Any clue what I am missing here ?

ASaiAnudeep commented 1 week ago

Hello @JyotiPMallick , is the RegisterCompany is a data template?

If so, we need to use @DATA:TEMPLATE@. For example:

spec.withMultiPartFormData({ '@DATA:TEMPLATE@': 'RegisterCompany' })
JyotiPMallick commented 1 week ago

You mean something like spec.withMultiPartFormData({ companyDto: {"@DATA:TEMPLATE@": "RegisterCompany" }}); ?

JyotiPMallick commented 1 week ago
addSpecHandler("Register a new company", ({ spec }) => {
  spec.post(paths.COMPANY_REGISTRATION);
  spec.withMultiPartFormData({ companyDto: {"@DATA:TEMPLATE@": "RegisterCompany" }});
  spec.expectStatus(200);
});

I am getting TypeError: source.on is not a function error.

ASaiAnudeep commented 1 week ago

Can you please share the stack trace of the error.

JyotiPMallick commented 1 week ago
  Registering a new company should return expected http status code 200 proper data in the response time.:
     TypeError: source.on is not a function
      at DelayedStream.create (node_modules\delayed-stream\lib\delayed_stream.js:33:10)
      at CombinedStream.append (node_modules\combined-stream\lib\combined_stream.js:45:37)
      at FormData.append (node_modules\form-data-lite\src\index.js:75:3)
      at setMultiPartFormData (node_modules\pactum\src\helpers\requestProcessor.js:134:34)
      at Object.process (node_modules\pactum\src\helpers\requestProcessor.js:22:5)
      at Tosser.toss (node_modules\pactum\src\models\Tosser.js:32:39)
      at Spec.toss (node_modules\pactum\src\models\Spec.js:540:19)
      at Spec.then (node_modules\pactum\src\models\Spec.js:544:10)

Here it is