I am writing test cases for Javascript using mocha. My code exactly looks like this apigee
This javascript is deployed in apigee cloud. Where it has access to platform variables. This is myscript my-code.js
var responseCode = parseInt(context.getVariable(properties.source));
var log = {
org: context.getVariable(organization.name),
env: context.getVariable(environment.name),
responseCode: responseCode,
isError: (responseCode >= 400)
};
if (log.isError) {
log.errorMessage = context.getVariable(flow.error.message);
}
var logglyRequest = new Request(
'https://loggly.com/aaa',
'POST',
{'Content-Type': 'application/json'},
JSON.stringify(log)
);
httpClient.send(logglyRequest);
javascript code would have access to properties.source at run time. Apigee platform has its own internal way of how jc access those params. My question is if I am writing test case for this jc, how would I mock the values for properties.source. I am able to mock function call context.getVariable(). I am getting ReferenceError: properties is not defined. Test script in same in the apigee link given.
Aucun commentaire:
Enregistrer un commentaire