I'm a noob with Node.js, mocha,chai, sinon and supertest. This is the function I have and need to test. It is in .js file that has
const request = require('request'); at the beginning
and exports
module.exports.getPermalink = getPermalink;
module.exports.request = request;
async function getPermalink(event_object) {
return new Promise(function (resolve, reject) {
request.post('https://slack.com/api/chat.getPermalink?token=..............................', function (error, response, body) {
if (error) {
reject("Can not get permalik to message.");
} else {
var bodyObj = JSON.parse(body);
if (bodyObj.ok == true) {
event_object.message_permalink = bodyObj.permalink;
event_object.message_permalink = event_object.message_permalink.replace(/\//gm, "\\/");
resolve(event_object);
} else {
reject("Can not get parse message permalink.");
}
}
});
});
}
Is this the right way to test this function (the part that requests from url) and if not what must I do?
describe('getPermalink', function () {
it('Should return permalink',function(done){
msg_functions.request.post('https://slack.com/api/chat.getPermalink?token=.............', function (error, response, body) {
expect(body,JSON).to.contain("true")
expect(body,JSON).to.contain("http")
done()
})
})