Hi All,
I am currently working on creating mocha unit test cases for the Javascript filles in our API Proxy but while running the test I am getting error - context.getVariable is not a function
I have also gone through similar community links but still the issue is not solved.
Below is my Javascript Code
File Name :- Apigee.js
var value = context.getVariable('request.header.ip');
context.setVariable('ip23',value);
File Name :- test.js
var expect = require('chai');
var sinon = require('sinon');
var rewire = require('rewire');
var mocks = require('apigee-edge-js');
var setCustomHeader = require('../app/apigee.js');
describe('Custom Header', function() {
it('should set request Header with Client IP', function() {
var mockContext=mocks.context();
sinon.stub(mockContext,'getVariable').withArgs('request.header.ip').returns('192.168.1.1');
setCustomHeader(mockContext);
expect(mockContext.getVariable.calledWith('request.header.ip')).to.be.true;
expect(mockContext.setVariable().calledWith('ip23','192.168.1.1')).to.be.true;
});
});
Please help me with the test.js code so that I can mock the context.getVariable/context.setVariable values and test the Files.
Thanks,
Hi All,
Can someone please help on the above query.
Thanks,