I am testing adding products, I want to add 10 products, but the problem is that I get an empty answer. I use the https://www.npmjs.com/package/multer library.
My test:
describe('POST /api/products/add', () => {
it(`Should create ${addProductCount} products with 0...1000 price`, (done) => {
let operationCount = addProductCount;
for (let i = 0; i < addProductCount; i++) {
chai
.request(server)
.post('api/products/add')
.set('token', constants.merchantToken)
.field('product_name', 'test')
.field('product_description', 'description description')
.field('original_price', '20')
.field('sale_price', '10')
.field('starting_date', '2019-04-19T17:03:00+00:00')
.field('end_date', '2019-04-19T20:03:00+00:00')
.field('quantity_available', '20')
.field('quantity_available', 'HOME APPLIANCES')
.attach('product_photos', fs.readFileSync(images1), 'test1.jpeg')
.attach('product_photos', fs.readFileSync(images2), 'test2.jpg')
.attach('product_photos', fs.readFileSync(images3), 'test3.png')
.end((err, res) => {
operationCount--;
expect(res).have.status(200);
expect(res.body).have.property('message');
expect(res.body.message).to.be.equal('Product added');
if (operationCount == 0) {
done();
}
});
}
});
});
When performing tests, I get an error:
Uncaught TypeError: Cannot use 'in' operator to search for 'status' in undefined at Proxy.<anonymous> (node_modules\chai-http\lib\http.js:80:38) at Proxy.methodWrapper >(node_modules\chai\lib\chai\utils\addMethod.js:57:25) at status (test/productsTest.js:73:42) at Test.Request.callback (node_modules\superagent\lib\node\index.js:728:3) at ClientRequest.req.once.err (node_modules\superagent\lib\node\index.js:647:10) at ClientRequest.EventEmitter.emit (domain.js:441:20) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.EventEmitter.emit (domain.js:441:20) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) at process._tickCallback (internal/process/next_tick.js:63:19)
When I do console.log(res)
I get undefined
When I do console.log(err)
I get:
{ Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
response: undefined }
Through the postman with this data, the product is added successfully. What is the problem of my test?
Aucun commentaire:
Enregistrer un commentaire