I made a connection to a database successfully, but I don't understand how I can invoke the method that brings me the information when the conditions of any of the predicates I made are met. This is my first time virtualizing services with Mountebank together with JavaScript and NodeJs. I hope someone can help me with this issue and the code is as follows:
const mbHelper = require('./mountebank-helper');
const settings = require('./settings');
const bdHelper = require('./accesoBD');
function wsCopagoService() {
var fs = require('fs');
const responseAuth = fs.readFileSync('src\\responses\\responseToken.json','utf8');
const responseConsultarOds = fs.readFileSync('src\\responses\\responseConsultaOds.json','utf8');
const token = JSON.parse(responseAuth)['token'];
bdHelper.conexion(555438338);//<---This is the method that I want to call when the validations of some predicate are met
const stubs = [
{
predicates: [
{ equals: { method: "POST" } },
{ equals: { headers: { "Content-Type": "text/plain" } } },
{ equals: { path: "/WSpago/api/token" } },
{
equals: {
body: {
"username": "CAMB_FIS",
"password": "Y21iRmlzRWt0UH"
}
}
}
],
responses: [
{
is: {
statusCode: 200,
headers: { "Content-Type": "application/json"},
body: responseAuth
}
}
],
},
{
predicates: [
{ equals: { method: "POST" } },
{
and:[
{ exists: { headers: {"Authorization": true} } },
{
equals: { headers: { "Authorization": "Bearer " + token } }
}
]
},
{ equals: { headers: { "Content-Type": "application/json" } } },
{ equals: { path: "/WSpago/api/consultarOds" } },
{
jsonpath: { selector: "$.ods" },
equals: { body: "555438338"}
}
],
responses: [
{
is: {
statusCode: 200,
headers: { "Content-Type": "application/json"},
body: responseConsultarOds
}
}
]
}
];
const imposter = {
port: settings.port_pago,
protocol: 'http',
stubs: stubs
};
return mbHelper.postImposter(imposter);
}
module.exports = { wsPagoService };