-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.js
56 lines (47 loc) · 1.32 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
// npm
import test from 'ava'
// self
import fn from './'
const expected = ['ip', 'hostname', 'city', 'region', 'country', 'loc', 'org', 'postal', 'timezone', 'readme']
test('self', async t => {
const result = await fn()
t.plan(2 * expected.length)
for (let r in result) {
t.truthy(result[r])
t.truthy(expected.indexOf(r) !== -1)
}
})
test('google', async t => {
const result = await fn('8.8.8.8')
t.is(result.ip, '8.8.8.8')
t.is(result.hostname, 'dns.google')
t.is(result.city, 'Mountain View')
t.is(result.region, 'California')
t.is(result.country, 'US')
t.is(result.loc, '37.4056,-122.0775')
t.is(result.org, 'AS15169 Google LLC')
t.is(result.postal, '94043')
})
test('google org', async t => {
const result = await fn('8.8.8.8/org')
t.is(result.trim(), 'AS15169 Google LLC')
})
test('google orga', async t => {
// FIXME: should probably fail
// or at least not return the string 'undefined\n'
const result = await fn('8.8.8.8/orga')
t.truthy(result)
})
test('not google', async t => {
try {
const result = await fn('8.8.8')
} catch (e) {
t.is(e.message, 'Please provide a valid IP address')
}
})
test('google with token', async t => {
const result = await fn('8.8.8.8', 'a-token-no-really')
// Fails due to invalid token
t.is(result.ip, undefined)
})