I have written a test case where I attach an image and a parameter {"name":"xyz"} to body. But in controller, req.body remains null. Please look at the attached code below. Where am I making mistake ?
//test.spec.js
const chai = require('chai');
const fs = require('fs');
const chaiHttp = require('chai-http');
const app = require('../../../../src/index');
const { subid } = require('./common.helper');
const { expect } = chai;
chai.use(chaiHttp);
describe('Test for user endpoint', () => {
describe('Test for POST route', () => {
it('should return 201 and create user with single image upload', async () => {
const res = await chai.request(app)
.post("/posts/v1/create")
.set("subid", subid)
.field('email', 'myemail@gmail.com')
.attach('multimedia', fs.readFileSync(`/home/shiveshk/Downloads/image-1.png`), 'image-1.png')
expect(res.status).to.equal(201);
console.log('RES', res.body.data)
})
})
})
// controller.js
exports.create = async (req, res, next) => {
console.log("\n==> req.body : ",req.body);
};