Added tests for IP detection.

This commit is contained in:
Mike Cao 2024-03-04 16:08:39 -08:00
parent c807c3a8e9
commit 3d343991dc
3 changed files with 31 additions and 9 deletions

View file

@ -0,0 +1,21 @@
import * as detect from '../detect';
const IP = '127.0.0.1';
test('getIpAddress: Custom header', () => {
process.env.CLIENT_IP_HEADER = 'x-custom-ip-header';
expect(detect.getIpAddress({ headers: { 'x-custom-ip-header': IP } } as any)).toEqual(IP);
});
test('getIpAddress: CloudFlare header', () => {
expect(detect.getIpAddress({ headers: { 'cf-connecting-ip': IP } } as any)).toEqual(IP);
});
test('getIpAddress: Standard header', () => {
expect(detect.getIpAddress({ headers: { 'x-forwarded-for': IP } } as any)).toEqual(IP);
});
test('getIpAddress: No header', () => {
expect(detect.getIpAddress({ headers: {} } as any)).toEqual(null);
});