Skip to content

Commit

Permalink
fix: fix DC and FM states mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jul 26, 2023
1 parent 63d3287 commit ef8eaf9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib/location/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const states: Record<string, string> = {
'Connecticut': 'CT',
'Delaware': 'DE',
'Washington, D.C.': 'DC',
'District Of Columbia': 'DC',
'Federated States Of Micronesia': 'FM',
'District of Columbia': 'DC',
'Federated States of Micronesia': 'FM',
'Florida': 'FL',
'Georgia': 'GA',
'Guam': 'GU',
Expand Down
16 changes: 16 additions & 0 deletions test/mocks/nock-geoip.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"asn": "80001",
"as": "The Constant Company LLC"
},
"washington": {
"country_code": "US",
"region_name": "District of Columbia",
"city_name": "Washington",
"latitude": 38.89539,
"longitude": -77.039476,
"asn": "40676",
"as": "Psychz Networks"
},
"emptyCity": {
"country_code": "US",
"region_name": "Texas",
Expand Down Expand Up @@ -236,6 +245,13 @@
"loc": "40.004,-74.004",
"org": "AS80004 InterBS S.R.L. (BAEHOST)"
},
"washington": {
"city": "Washington",
"region": "Washington, D.C.",
"country": "US",
"loc": "38.8951,-77.0364",
"org": "AS701 Verizon Business"
},
"emptyNetwork": {
"city": "Dallas",
"region": "Texas",
Expand Down
42 changes: 41 additions & 1 deletion test/tests/unit/geoip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe('geoip service', () => {
});
});

it('should pick another provider if prioritized don\'t have city value', async () => {
it('should pick another provider if prioritized doesn\'t have city value', async () => {
nockGeoIpProviders({ ip2location: 'emptyCity', ipmap: 'emptyCity', maxmind: 'emptyCity' });

const info = await client.lookup(MOCK_IP);
Expand Down Expand Up @@ -354,6 +354,46 @@ describe('geoip service', () => {
});
});

it('should parse region properly even with wrong case spelling', async () => {
nockGeoIpProviders({ ip2location: 'washington', ipmap: 'emptyCity', maxmind: 'emptyCity', ipinfo: 'emptyCity', fastly: 'emptyCity' });

const info = await client.lookup(MOCK_IP);

expect(info).to.deep.equal({
continent: 'NA',
country: 'US',
state: 'DC',
city: 'Washington',
region: 'Northern America',
normalizedRegion: 'northern america',
normalizedCity: 'washington',
asn: 40676,
latitude: 38.89539,
longitude: -77.039476,
network: 'Psychz Networks',
normalizedNetwork: 'psychz networks',
});

nockGeoIpProviders({ ip2location: 'emptyCity', ipmap: 'emptyCity', maxmind: 'emptyCity', ipinfo: 'washington', fastly: 'emptyCity' });

const info2 = await client.lookup(MOCK_IP);

expect(info2).to.deep.equal({
continent: 'NA',
country: 'US',
state: 'DC',
city: 'Washington',
region: 'Northern America',
normalizedRegion: 'northern america',
normalizedCity: 'washington',
asn: 701,
latitude: 38.8951,
longitude: -77.0364,
network: 'Verizon Business',
normalizedNetwork: 'verizon business',
});
});

it('should fail (missing network data + city mismatch)', async () => {
nockGeoIpProviders({ ip2location: 'argentina', ipmap: 'newYork', maxmind: 'emptyNetwork', ipinfo: 'emptyNetwork', fastly: 'emptyCity' });

Expand Down

0 comments on commit ef8eaf9

Please sign in to comment.