fix(ipintelligence): handle flat geolocation MMDB schema and clean up DNS client lifecycle
This commit is contained in:
@@ -8,6 +8,24 @@ tap.test('should create a SmartNetwork instance', async () => {
|
||||
expect(testSmartNetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
||||
});
|
||||
|
||||
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.asnOrg).toBeTruthy();
|
||||
|
||||
// Geolocation
|
||||
expect(result.countryCode).toEqual('US');
|
||||
expect(result.latitude).not.toBeNull();
|
||||
expect(result.longitude).not.toBeNull();
|
||||
|
||||
// RDAP registration
|
||||
expect(result.registrantOrg).toBeTruthy();
|
||||
expect(result.networkRange).toBeTruthy();
|
||||
});
|
||||
|
||||
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));
|
||||
@@ -16,24 +34,11 @@ tap.test('should get IP intelligence for 1.1.1.1 (Cloudflare)', async () => {
|
||||
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();
|
||||
});
|
||||
expect(result.registrantCountry).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();
|
||||
// Note: 1.1.1.1 is anycast — city-level geo may be null in GeoLite2
|
||||
});
|
||||
|
||||
tap.test('should get IP intelligence for own public IP', async () => {
|
||||
@@ -42,7 +47,7 @@ tap.test('should get IP intelligence for own public IP', async () => {
|
||||
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();
|
||||
expect(result.countryCode).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -55,12 +60,11 @@ tap.test('should handle invalid IP gracefully', async () => {
|
||||
|
||||
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');
|
||||
const r1 = await cached.getIpIntelligence('8.8.8.8');
|
||||
const r2 = await cached.getIpIntelligence('8.8.8.8');
|
||||
// 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);
|
||||
expect(r1.countryCode).toEqual(r2.countryCode);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user