I have the following endpoint for validating a JSON file and I am using an integration test for the same. I use Mocha for testing and the code is as follows:
const request = require('supertest');
const app = require('../..//app.js');
describe.only('GET /validate', function() {
it('Return pricing file validation result', function(done) {
return request(app)
.get('/api/validate')
.expect(200)
.expect('Content-Type',/json/)
.expect('{"status":"success","message":"Pricing file validation completed successfully"}')
.end(function(err, res) {
if (err) return done(err);
done();
});
})
})
and the endpoint is mapped to :
export const validatePricing = (req, res) => {
validatePricingFile('./pricing_qa.json').then(r =>{
res.status(200).json({
status:"success",
message: 'Pricing file validation completed successfully'
})
}).catch(error=>{
console.log(error)
res.status(422).json({
'status':"error",
message: error.message
})
})
}
The validatePricingFile
returns a promise as follows:
return new Promise((resolve, reject) => {
const ajValidator = new ajv({allErrors: true});
const validate = ajValidator.compile(pricingSchema);
const valid = validate(pricingData);
if (!valid) {
return reject({
message:validate.errors
})
} else {
resolve(true)
}
})
When I run the test, I am getting the following error:
Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both.
How can I fix this and run the tests ?