Files
umami/src/lib/detect.test.ts
T
2026-05-14 22:05:34 -07:00

23 lines
645 B
TypeScript

import { expect, test } from 'vitest';
import { getIpAddress } from './ip';
const IP = '127.0.0.1';
test('getIpAddress: Custom header', () => {
process.env.CLIENT_IP_HEADER = 'x-custom-ip-header';
expect(getIpAddress(new Headers({ 'x-custom-ip-header': IP }))).toEqual(IP);
});
test('getIpAddress: CloudFlare header', () => {
expect(getIpAddress(new Headers({ 'cf-connecting-ip': IP }))).toEqual(IP);
});
test('getIpAddress: Standard header', () => {
expect(getIpAddress(new Headers({ 'x-forwarded-for': IP }))).toEqual(IP);
});
test('getIpAddress: No header', () => {
expect(getIpAddress(new Headers())).toEqual(undefined);
});