Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Feb 2, 2025
1 parent 6ab7746 commit 7e2d257
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/__tests__/detect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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);
expect(detect.getIpAddress(new Headers({ 'x-custom-ip-header': IP }))).toEqual(IP);
});

test('getIpAddress: CloudFlare header', () => {
expect(detect.getIpAddress({ headers: { 'cf-connecting-ip': IP } } as any)).toEqual(IP);
expect(detect.getIpAddress(new Headers({ 'cf-connecting-ip': IP }))).toEqual(IP);
});

test('getIpAddress: Standard header', () => {
expect(detect.getIpAddress({ headers: { 'x-forwarded-for': IP } } as any)).toEqual(IP);
expect(detect.getIpAddress(new Headers({ 'x-forwarded-for': IP }))).toEqual(IP);
});

test('getIpAddress: No header', () => {
expect(detect.getIpAddress({ headers: {} } as any)).toEqual(null);
expect(detect.getIpAddress(new Headers())).toEqual(null);
});
2 changes: 1 addition & 1 deletion src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getIpAddress(headers: Headers) {
const ip = headers.get(header);

if (header === 'x-forwarded-for') {
return ip?.split[',']?.[0]?.trim();
return ip?.split(',')?.[0]?.trim();
}

if (header === 'forwarded') {
Expand Down

0 comments on commit 7e2d257

Please sign in to comment.