Unit tests failing with context.getvariable not a function
import expect from 'expect.js';
import sinon from 'sinon';
import rewire from 'rewire'; // Use import instead of require
import { isIPInRange } from '../../test.js'; // ES module import
// Create a mock context
const fakeContext = {
getVariable: sinon.stub(),
setVariable: sinon.stub(),
};
describe('IP Range Checking', function () {
describe('isIPInRange', function () {
it('should mock context.getVariable for test', function () {
// Arrange: Create mocks for context
fakeContext.getVariable
.withArgs('verifyapikey.VAK-VerifyAPIKey.allowlist')
.returns('192.168.1.0/24,10.0.0.0/8');
fakeContext.getVariable
.withArgs('asapp.shared.trueClientIP')
.returns('192.168.1.50');
// Act: Call the function with the mocked context
const found = isIPInRange('192.168.1.50', ['192.168.1.0/24', '10.0.0.0/8']);
// Assert: Check if IP is in range (based on the mock)
expect(found).to.be.true;
});
});
});