forked from richorama/country-code-lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
114 lines (96 loc) · 3.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var countries = require('./index.js')
describe('country code', function() {
it('loads the countries into an array', function(done) {
if (countries.countries.length < 239)
return done(
'not all countries loaded, found ' + countries.countries.length
)
return done()
})
it('finds countries by fips', function(done) {
var uk = countries.byFips('UK')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
if (uk.continent !== 'Europe') return done('wrong continent')
if (uk.region !== 'Western Europe') return done('wrong region')
if (uk.capital !== 'London') return done('wrong capital')
return done()
})
it('finds countries by iso 2', function(done) {
var uk = countries.byIso('GB')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('finds countries by iso 3', function(done) {
var uk = countries.byIso('GBR')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('finds countries by iso number', function(done) {
var uk = countries.byIso(826)
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('finds countries by country name', function(done) {
var uk = countries.byCountry('United Kingdom')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
if (uk.continent !== 'Europe') return done('wrong continent')
if (uk.region !== 'Western Europe') return done('wrong region')
if (uk.capital !== 'London') return done('wrong capital')
return done()
})
it('finds countries by iso number as a string', function(done) {
var uk = countries.byIso('826')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('finds countries by internet code', function(done) {
var uk = countries.byInternet('UK')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('finds countries by lower case fips', function(done) {
var uk = countries.byFips('uk')
if (!uk) return done('no country')
if (uk.country !== 'United Kingdom') return done('wrong country')
return done()
})
it('throws an error if the iso code is invalid', function(done) {
try {
var uk = countries.byIso('foo bar baz')
return done('exception should be thrown')
} catch (e) {
return done()
}
})
it('returns null if no country is found', function(done) {
var uk = countries.byIso(23452)
if (uk === null) return done()
return done('country should be null')
})
it('Romania is now ROU', function(done) {
var romania = countries.byIso('ROM')
if (null !== romania) return done('Romania is no longer ROM')
var romania = countries.byIso('ROU')
if (null === romania) return done('Romania is now ROU')
done()
})
it('Democratic Republic of Congo', function(done) {
var drcongo = countries.byIso('COD')
if (null == drcongo) return done('Democratic Republic of Congo is COD')
var drcongo = countries.byIso('CD')
if (null == drcongo) return done('Democratic Republic of Congo is CD')
done()
})
it('Zambia is ZMB', function(done) {
var zambia = countries.byIso('ZMB')
if (null == zambia) return done('Zambia is ZMB')
done()
})
})