-
Notifications
You must be signed in to change notification settings - Fork 11
/
country_mapper_test.go
139 lines (125 loc) · 3.49 KB
/
country_mapper_test.go
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package country_mapper
import (
"testing"
"github.com/stretchr/testify/assert"
)
var mockClient *CountryInfoClient
//===========================================
// Setup Tests
//===========================================
func Test_Init(t *testing.T) {
client, err := Load()
assert.Nil(t, err)
mockClient = client
}
//===========================================
// CountryInfoClient MapByName
//===========================================
func Test_Client_MapByName(t *testing.T) {
// should map by name
ret := mockClient.MapByName("South Korea")
assert.Equal(t, ret.Name, "South Korea")
assert.Equal(t, ret.Alpha2, "KR")
assert.Equal(t, ret.Alpha3, "KOR")
assert.Equal(t, ret.Capital, "Seoul")
assert.Equal(t, ret.Currency, []string{"KRW"})
assert.Equal(t, ret.CallingCode, []string{"82"})
assert.Equal(t, ret.Region, "Asia")
assert.Equal(t, ret.Subregion, "Eastern Asia")
// should be able to map different variations of name
ret = mockClient.MapByName("south korea")
assert.Equal(t, ret.Name, "South Korea")
ret = mockClient.MapByName("대한민국")
assert.Equal(t, ret.Name, "South Korea")
// should return nil when you try to map names not commonly used
ret = mockClient.MapByName("southkorea")
assert.Nil(t, ret)
}
//===========================================
// CountryInfoClient MapByAlpha2
//===========================================
func Test_Client_MapByAlpha2(t *testing.T) {
ret := mockClient.MapByAlpha2("SG")
assert.Equal(t, ret.Name, "Singapore")
}
//===========================================
// CountryInfoClient MapByAlpha3
//===========================================
func Test_Client_MapByAlpha3(t *testing.T) {
ret := mockClient.MapByAlpha3("SGP")
assert.Equal(t, ret.Name, "Singapore")
}
//===========================================
// CountryInfoClient MapByCurrency
//===========================================
func Test_Client_MapByCurrency(t *testing.T) {
ret := mockClient.MapByCurrency("SGD")
assert.Equal(t, ret[0].Name, "Singapore")
}
//===========================================
// CountryInfoClient MapByCallingCode
//===========================================
func Test_Client_MapByCallingCode(t *testing.T) {
ret := mockClient.MapByCallingCode("65")
assert.Equal(t, ret[0].Name, "Singapore")
}
//===========================================
// CountryInfoClient MapByRegion
//===========================================
func Test_Client_MapByRegion(t *testing.T) {
countriesInOceania := []string{
"American Samoa",
"Australia",
"Christmas Island",
"Cocos (Keeling) Islands",
"Cook Islands",
"Fiji",
"French Polynesia",
"Guam",
"Kiribati",
"Marshall Islands",
"Micronesia",
"Nauru",
"New Caledonia",
"New Zealand",
"Niue",
"Norfolk Island",
"Northern Mariana Islands",
"Palau",
"Papua New Guinea",
"Pitcairn Islands",
"Samoa",
"Solomon Islands",
"Tokelau",
"Tonga",
"Tuvalu",
"Vanuatu",
"Wallis and Futuna",
}
ret := mockClient.MapByRegion("Oceania")
for _, row := range ret {
assert.Contains(t, countriesInOceania, row.Name)
}
}
//===========================================
// CountryInfoClient MapBySubregion
//===========================================
func Test_Client_MapBySubregion(t *testing.T) {
countriesInSEA := []string{
"Brunei",
"Cambodia",
"Indonesia",
"Laos",
"Malaysia",
"Myanmar",
"Philippines",
"Singapore",
"Thailand",
"Timor-Leste",
"Vietnam",
}
ret := mockClient.MapBySubregion("South-Eastern Asia")
for _, row := range ret {
assert.Contains(t, countriesInSEA, row.Name)
}
}