-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturkish_cities_test.go
258 lines (204 loc) · 5.28 KB
/
turkish_cities_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package turkish_cities
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestLoad(t *testing.T) {
t.Run("should load the data", func(t *testing.T) {
tc := Load()
assert.NotEmpty(t, tc.GetCities())
assert.Equal(t, 81, len(tc.GetCities()))
})
}
func TestTurkishCities_GetCities(t *testing.T) {
t.Run("should return cities", func(t *testing.T) {
tc := TurkishCities{
Cities: []City{
{
BaseEntity: BaseEntity{
ID: 1,
Name: "Adana",
},
},
{
BaseEntity: BaseEntity{
ID: 2,
Name: "Adıyaman",
},
},
},
}
assert.Equal(t, 2, len(tc.GetCities()))
})
t.Run("should return empty cities", func(t *testing.T) {
tc := TurkishCities{}
assert.Empty(t, tc.GetCities())
})
t.Run("should return loaded cities", func(t *testing.T) {
tc := Load()
assert.NotEmpty(t, tc.GetCities())
})
}
func TestCity_GetTowns(t *testing.T) {
t.Run("should return towns", func(t *testing.T) {
c := City{
Towns: []Town{
{
BaseEntity: BaseEntity{
ID: 1,
Name: "Seyhan",
},
},
{
BaseEntity: BaseEntity{
ID: 2,
Name: "Yüreğir",
},
},
},
}
assert.Equal(t, 2, len(c.GetTowns()))
})
t.Run("should return empty towns", func(t *testing.T) {
c := City{}
assert.Empty(t, c.GetTowns())
})
t.Run("should return loaded towns", func(t *testing.T) {
tc := Load()
c := tc.GetCities()[0]
assert.NotEmpty(t, c.GetTowns())
})
}
func TestTown_GetDistricts(t *testing.T) {
t.Run("should return districts", func(t *testing.T) {
town := Town{
Districts: []District{
{
BaseEntity: BaseEntity{
ID: 1,
Name: "Seyhan",
},
},
{
BaseEntity: BaseEntity{
ID: 2,
Name: "Yüreğir",
},
},
},
}
assert.Equal(t, 2, len(town.GetDistricts()))
})
t.Run("should return empty districts", func(t *testing.T) {
town := Town{}
assert.Empty(t, town.GetDistricts())
})
t.Run("should return loaded districts", func(t *testing.T) {
tc := Load()
c := tc.GetCities()[0]
town := c.GetTowns()[0]
assert.NotEmpty(t, town.GetDistricts())
})
}
func TestDistrict_GetQuarters(t *testing.T) {
t.Run("should return quarters", func(t *testing.T) {
district := District{
Quarters: []Quarter{
{
BaseEntity: BaseEntity{
ID: 1,
Name: "Seyhan",
},
},
{
BaseEntity: BaseEntity{
ID: 2,
Name: "Yüreğir",
},
},
},
}
assert.Equal(t, 2, len(district.GetQuarters()))
})
t.Run("should return empty quarters", func(t *testing.T) {
district := District{}
assert.Empty(t, district.GetQuarters())
})
t.Run("should return loaded quarters", func(t *testing.T) {
tc := Load()
c := tc.GetCities()[0]
town := c.GetTowns()[0]
district := town.GetDistricts()[0]
assert.NotEmpty(t, district.GetQuarters())
})
}
func TestTurkishCities_GetCountry(t *testing.T) {
t.Run("should return country", func(t *testing.T) {
tc := Load()
assert.NotEmpty(t, tc.GetCountry())
assert.Equal(t, "Türkiye", tc.GetCountry().Name)
assert.Equal(t, "+90", tc.GetCountry().PhoneCode)
assert.Equal(t, "TR", tc.GetCountry().Alpha2Code)
assert.Equal(t, "TUR", tc.GetCountry().Alpha3Code)
assert.Equal(t, "TR", tc.GetCountry().Abbreviation)
})
}
func TestTurkishCities_GetCityByID(t *testing.T) {
t.Run("should return city by id", func(t *testing.T) {
tc := Load()
assert.NotNil(t, tc.GetCityByID(1))
assert.Equal(t, "Adana", tc.GetCityByID(1).Name)
})
t.Run("should return nil for unknown city id", func(t *testing.T) {
tc := Load()
assert.Nil(t, tc.GetCityByID(100))
})
}
func TestTurkishCities_GetTownByID(t *testing.T) {
t.Run("should return town by id", func(t *testing.T) {
tc := Load()
randomCity := tc.GetCities()[0]
randomTown := randomCity.GetTowns()[0]
result := tc.GetTownByID(randomCity.ID, randomTown.ID)
assert.NotNil(t, result)
assert.Equal(t, randomTown.Name, result.Name)
})
t.Run("should return nil for unknown town id", func(t *testing.T) {
tc := Load()
result := tc.GetTownByID(1, 999)
assert.Nil(t, result)
})
}
func TestTurkishCities_GetDistrictByID(t *testing.T) {
t.Run("should return district by id", func(t *testing.T) {
tc := Load()
randomCity := tc.GetCities()[0]
randomTown := randomCity.GetTowns()[0]
randomDistrict := randomTown.GetDistricts()[0]
result := tc.GetDistrictByID(randomCity.ID, randomTown.ID, randomDistrict.ID)
assert.NotNil(t, result)
assert.Equal(t, randomDistrict.Name, result.Name)
})
t.Run("should return nil for unknown district id", func(t *testing.T) {
tc := Load()
result := tc.GetDistrictByID(1, 1, 999)
assert.Nil(t, result)
})
}
func TestTurkishCities_GetQuarterByID(t *testing.T) {
t.Run("should return quarter by id", func(t *testing.T) {
tc := Load()
randomCity := tc.GetCities()[0]
randomTown := randomCity.GetTowns()[0]
randomDistrict := randomTown.GetDistricts()[0]
randomQuarter := randomDistrict.GetQuarters()[0]
result := tc.GetQuarterByID(randomCity.ID, randomTown.ID, randomDistrict.ID, randomQuarter.ID)
assert.NotNil(t, result)
assert.Equal(t, randomQuarter.Name, result.Name)
})
t.Run("should return nil for unknown quarter id", func(t *testing.T) {
tc := Load()
result := tc.GetQuarterByID(1, 1, 1, 999)
assert.Nil(t, result)
})
}