I have a JavaScript policy as below, with multiple js files where, JS-Transform-GetEntityRequestV3.js invokes the function “jsonPath(obj, expr, arg){…}” from jsonpath-0.8.0.js
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="JS-Transform-Response">
<Properties/>
<ResourceURL>jsc://JS-Transform-GetEntityRequestMain.js</ResourceURL>
<IncludeURL>jsc://JS-Transform-GetEntityRequestV3.js</IncludeURL>
<IncludeURL>jsc://jsonpath-0.8.0.js</IncludeURL>
</Javascript>
I am trying to write test cases using mocha/chai/sinon for JS-Transform-GetEntityRequestV3.js and getting “ReferenceError: jsonPath is not defined” as the function is in another js file. Could you please let me know if there is a way to handle this rather than moving the jsonPath() function to the same js file?
Any help would be appreciated
Below is my test code:
var assert = require('chai').assert;
var sinon = require('sinon');
var rewire = require('rewire');
var transformFunctions = rewire('../transform/JS-Transform-GetEntityRequestV3.js');
var jsonpathFunctions = rewire('../transform/jsonpath-0.8.0.js');
var result = {
"uri": "entities/157KsIFj",
"type": "configuration/entityTypes/Guest"
describe('GET transformation logic functions', () =>{
it('Map Addresses', () =>{
var mapAddress = transformFunctions.__get__ ('mapAddress');
var attributes = result.attributes
var mappedAddress = mapAddress(attributes);
assert.isNotNull(mappedAddress, 'returned mapped address');
});
});