-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Use mock API when running tests (#95)
- Loading branch information
Showing
15 changed files
with
1,503 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"ip": "198.51.100.1", | ||
"bogon": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"ip": "8.8.8.8", | ||
"hostname": "dns.google", | ||
"anycast": true, | ||
"city": "Mountain View", | ||
"region": "California", | ||
"country": "US", | ||
"loc": "37.4056,-122.0775", | ||
"org": "AS15169 Google LLC", | ||
"postal": "94043", | ||
"timezone": "America/Los_Angeles", | ||
"asn": { | ||
"asn": "AS15169", | ||
"name": "Google LLC", | ||
"domain": "google.com", | ||
"route": "8.8.8.0/24", | ||
"type": "hosting" | ||
}, | ||
"company": { | ||
"name": "Google LLC", | ||
"domain": "google.com", | ||
"type": "hosting" | ||
}, | ||
"privacy": { | ||
"vpn": false, | ||
"proxy": false, | ||
"tor": false, | ||
"relay": false, | ||
"hosting": true, | ||
"service": "" | ||
}, | ||
"abuse": { | ||
"address": "US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"name": "Abuse", | ||
"network": "8.8.8.0/24", | ||
"phone": "+1-650-253-0000" | ||
}, | ||
"domains": { | ||
"ip": "8.8.8.8", | ||
"total": 12095, | ||
"domains": [ | ||
"hdchina.org", | ||
"musicool.cn", | ||
"allnet.cn", | ||
"aonode.com", | ||
"didifilm.com" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"asn": "AS7922", | ||
"name": "Comcast Cable Communications, LLC", | ||
"country": "US", | ||
"allocated": "1997-02-14", | ||
"registry": "arin", | ||
"domain": "comcast.com", | ||
"num_ips": 70110720, | ||
"type": "isp", | ||
"prefixes": [ | ||
{ | ||
"netblock": "107.0.0.0/14", | ||
"id": "JUMPSTART-5", | ||
"name": "Comcast Cable Communications, LLC", | ||
"country": "US", | ||
"size": "262144", | ||
"status": "ALLOCATION", | ||
"domain": "comcast.com" | ||
}, | ||
{ | ||
"netblock": "107.4.0.0/15", | ||
"id": "MICHIGAN-39", | ||
"name": "Comcast Cable Communications, Inc.", | ||
"country": "US", | ||
"size": "131072", | ||
"status": "REASSIGNMENT", | ||
"domain": "comcast.net" | ||
} | ||
], | ||
"peers": ["1273", "109"], | ||
"upstreams": ["6453", "1299"], | ||
"downstreams": ["398465", "32244"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"8.8.8.8/hostname": "dns.google", | ||
"4.4.4.4": { | ||
"ip": "4.4.4.4", | ||
"city": "Weda", | ||
"region": "North Maluku", | ||
"country": "ID", | ||
"loc": "0.3295,127.8739", | ||
"org": "AS3356 Level 3 Parent, LLC", | ||
"timezone": "Asia/Jayapura", | ||
"asn": { | ||
"asn": "AS3356", | ||
"name": "Level 3 Parent, LLC", | ||
"domain": "lumen.com", | ||
"route": "4.0.0.0/9", | ||
"type": "isp" | ||
}, | ||
"company": { | ||
"name": "Level 3 Parent, LLC", | ||
"domain": "level3.com", | ||
"type": "isp" | ||
}, | ||
"privacy": { | ||
"vpn": false, | ||
"proxy": false, | ||
"tor": false, | ||
"relay": false, | ||
"hosting": false, | ||
"service": "" | ||
}, | ||
"abuse": { | ||
"address": "US, LA, Monroe, 100 CenturyLink Drive, 71203", | ||
"country": "US", | ||
"email": "[email protected]", | ||
"name": "L3 Abuse Contact", | ||
"network": "4.0.0.0/9", | ||
"phone": "+1-877-453-8353" | ||
}, | ||
"domains": { | ||
"ip": "4.4.4.4", | ||
"total": 114, | ||
"domains": [ | ||
"itmanagementgroup.de", | ||
"safermoto.com", | ||
"progeni.com", | ||
"grahamhostedservices.com", | ||
"bhcentral.tech" | ||
] | ||
} | ||
}, | ||
"AS123": { | ||
"asn": "AS123", | ||
"name": "Air Force Systems Networking", | ||
"country": "US", | ||
"allocated": "1987-08-24", | ||
"registry": "arin", | ||
"domain": "af.mil", | ||
"num_ips": 0, | ||
"type": "inactive", | ||
"prefixes": [], | ||
"prefixes6": [], | ||
"peers": null, | ||
"upstreams": null, | ||
"downstreams": null, | ||
"countryCode": "US" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"status": "Report Generated", | ||
"reportUrl": "https://ipinfo.io/tools/map/example" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,14 @@ let ipinfoWrapper: IPinfoWrapper; | |
|
||
beforeEach(() => { | ||
dotenv.config(); | ||
const token = process.env.IPINFO_TOKEN || ""; | ||
|
||
if (!token) { | ||
throw new Error( | ||
"Tests require a token in the IPINFO_TOKEN Environment Variable." | ||
); | ||
} | ||
|
||
ipinfoWrapper = new IPinfoWrapper(token); | ||
ipinfoWrapper = new IPinfoWrapper( | ||
"example-token", | ||
undefined, | ||
undefined, | ||
{}, | ||
"http://127.0.0.1:9090" | ||
); | ||
}); | ||
|
||
describe("IPinfoWrapper", () => { | ||
|
@@ -90,6 +89,10 @@ describe("IPinfoWrapper", () => { | |
expect(data.domain).toEqual("comcast.com"); | ||
expect(data.num_ips).not.toBeFalsy(); | ||
expect(data.type).toEqual("isp"); | ||
expect(data.prefixes.length).toEqual(2); | ||
expect(data.peers.length).toEqual(2); | ||
expect(data.upstreams.length).toEqual(2); | ||
expect(data.downstreams.length).toEqual(2); | ||
} | ||
}); | ||
|
||
|
@@ -121,6 +124,7 @@ describe("IPinfoWrapper", () => { | |
city: "Weda", | ||
region: "North Maluku", | ||
country: "Indonesia", | ||
countryCode: "ID", | ||
loc: "0.3295,127.8739", | ||
org: "AS3356 Level 3 Parent, LLC", | ||
timezone: "Asia/Jayapura", | ||
|
@@ -147,24 +151,23 @@ describe("IPinfoWrapper", () => { | |
abuse: { | ||
address: "US, LA, Monroe, 100 CenturyLink Drive, 71203", | ||
country: "United States", | ||
countryCode: "US", | ||
email: "[email protected]", | ||
name: "L3 Abuse Contact", | ||
network: "4.0.0.0/9", | ||
phone: "+1-877-453-8353", | ||
countryCode: "US" | ||
phone: "+1-877-453-8353" | ||
}, | ||
domains: { | ||
ip: "4.4.4.4", | ||
total: 111, | ||
total: 114, | ||
domains: [ | ||
"itmanagementgroup.de", | ||
"safermoto.com", | ||
"progeni.com", | ||
"grahamhostedservices.com", | ||
"bhcentral.tech" | ||
] | ||
}, | ||
countryCode: "ID" | ||
} | ||
}); | ||
|
||
expect(data["AS123"]).toEqual({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fakeServer = require("test-fake-server"); | ||
const path = require("path"); | ||
|
||
module.exports = async function globalSetup() { | ||
const model = { | ||
port: 9090, | ||
api: [ | ||
{ | ||
method: "GET", | ||
path: "/8.8.8.8/json", | ||
response: path.resolve(__dirname, "./fixtures/8.8.8.8.json") | ||
}, | ||
{ | ||
method: "GET", | ||
path: "/198.51.100.1/json", | ||
response: path.resolve( | ||
__dirname, | ||
"./fixtures/198.51.100.1.json" | ||
) | ||
}, | ||
{ | ||
method: "GET", | ||
path: "/AS7922/json", | ||
response: path.resolve(__dirname, "./fixtures/AS7922.json") | ||
}, | ||
{ | ||
method: "POST", | ||
path: "/batch", | ||
response: path.resolve(__dirname, "./fixtures/batch.json") | ||
}, | ||
{ | ||
method: "POST", | ||
path: "/tools/map", | ||
response: path.resolve(__dirname, "./fixtures/tools/map.json") | ||
} | ||
] | ||
}; | ||
|
||
globalThis.server = await fakeServer(model); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = async function globalTeardown() { | ||
await globalThis.server.stop(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.