Commit a65ff14a authored by peterhegman's avatar peterhegman

Switch to mocking `ipaddr.isValid`

parent c0925e88
import * as validateIpAddress from 'ee/validators/ip_address';
import ipaddr from 'ipaddr.js';
import validateRestrictedIpAddress from 'ee/groups/settings/access_restriction_field/validate_ip_address';
describe('validateRestrictedIpAddress', () => {
describe('when `validateIpAddress` returns false', () => {
describe('when IP address is not valid', () => {
it('returns an error message', () => {
validateIpAddress.default = jest.fn(() => false);
ipaddr.isValid = jest.fn(() => false);
expect(validateRestrictedIpAddress('foo bar')).toBe(`foo bar is an invalid IP address range`);
const result = validateRestrictedIpAddress('foo bar');
expect(ipaddr.isValid).toHaveBeenCalledWith('foo bar');
expect(result).toBe(`foo bar is an invalid IP address range`);
});
});
describe('when IP address is valid', () => {
it('returns an empty string', () => {
validateIpAddress.default = jest.fn(() => true);
ipaddr.isValid = jest.fn(() => true);
const result = validateRestrictedIpAddress('192.168.0.0');
expect(validateRestrictedIpAddress('192.168.0.0/24')).toBe('');
expect(ipaddr.isValid).toHaveBeenCalledWith('192.168.0.0');
expect(result).toBe('');
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment