import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as smartnetwork from '../ts/index.js'; let testSmartNetwork: smartnetwork.SmartNetwork; tap.test('should create a SmartNetwork instance', async () => { testSmartNetwork = new smartnetwork.SmartNetwork(); expect(testSmartNetwork).toBeInstanceOf(smartnetwork.SmartNetwork); }); tap.test('should get IP intelligence for 1.1.1.1 (Cloudflare)', async () => { const result = await testSmartNetwork.getIpIntelligence('1.1.1.1'); console.log('IP Intelligence for 1.1.1.1:', JSON.stringify(result, null, 2)); // ASN should be Cloudflare's 13335 expect(result.asn).toEqual(13335); expect(result.asnOrg).toBeTruthy(); // Geolocation should be present expect(result.country).toBeTruthy(); expect(result.countryCode).toBeTruthy(); expect(result.latitude).not.toBeNull(); expect(result.longitude).not.toBeNull(); // RDAP registration data should be present expect(result.networkRange).toBeTruthy(); }); tap.test('should get IP intelligence for 8.8.8.8 (Google)', async () => { const result = await testSmartNetwork.getIpIntelligence('8.8.8.8'); console.log('IP Intelligence for 8.8.8.8:', JSON.stringify(result, null, 2)); // Google's ASN is 15169 expect(result.asn).toEqual(15169); expect(result.country).toBeTruthy(); expect(result.countryCode).toBeTruthy(); }); tap.test('should get IP intelligence for own public IP', async () => { const ips = await testSmartNetwork.getPublicIps(); if (ips.v4) { const result = await testSmartNetwork.getIpIntelligence(ips.v4); console.log(`IP Intelligence for own IP (${ips.v4}):`, JSON.stringify(result, null, 2)); expect(result.asn).toBeTypeofNumber(); expect(result.country).toBeTruthy(); } }); tap.test('should handle invalid IP gracefully', async () => { const result = await testSmartNetwork.getIpIntelligence('999.999.999.999'); console.log('IP Intelligence for invalid IP:', JSON.stringify(result, null, 2)); // Should return nulls without throwing expect(result).toBeTruthy(); }); tap.test('should use cache when cacheTtl is set', async () => { const cached = new smartnetwork.SmartNetwork({ cacheTtl: 60000 }); const r1 = await cached.getIpIntelligence('1.1.1.1'); const r2 = await cached.getIpIntelligence('1.1.1.1'); // Second call should return the same cached result expect(r1.asn).toEqual(r2.asn); expect(r1.country).toEqual(r2.country); expect(r1.city).toEqual(r2.city); }); export default tap.start();