I am testing adding products, I want to add 10 products, but the problem is that I cannot transfer the image to the multer library.
My code is:
import { expect } from 'chai';
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from '../src/index';
import db from '../src/db/database';
chai.use(chaiHttp);
import constants from './tool/constants';
import utils from './tool/utils';
let addProductCount = 10;
describe('Test products', () => {
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++) {
let product = utils.getFakeProduct(2, 1000);
chai.request(server)
.post('api/products/add')
.set('token', constants.merchantToken)
.send(product)
.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();
}
});
}
});
});
});
...
function getFakeProduct(lowerPrice, upperPrice) {
let currentDate = faker.date.recent();
let original_price = getRandomInt(lowerPrice, upperPrice);
return {
product_name: faker.commerce.productName(),
product_description: `${faker.commerce.productAdjective()} ${faker.commerce.productAdjective()}`,
original_price,
sale_price: original_price - getRandomInt(lowerPrice, original_price - 1),
starting_date: currentDate,
end_date: moment(currentDate).add(1, 'days'),
product_photos: faker.image.image(),
quantity_available: faker.random.number(50),
categories: 'HOME APPLIANCES',
};
}
...
I get an error Uncaught TypeError: Cannot use 'in' operator to search for 'status' in undefined
.
How to test the multer library? How to transfer the photo to the library so that the test runs? Why the test fails I ponma, problems with the image
Aucun commentaire:
Enregistrer un commentaire