Skip to content

Commit 2668ac8

Browse files
committed
test: find alpha2 by currency
1 parent 33d4a30 commit 2668ac8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

query_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,40 @@ func TestFindCountryByCallingCode(t *testing.T) {
397397
})
398398
}
399399
}
400+
401+
func TestFindCountriesByCurrency(t *testing.T) {
402+
tests := []struct {
403+
name string
404+
currency string
405+
expectedError error
406+
expectedCountry int
407+
}{
408+
{
409+
name: "Find countries by valid currency should return countries when currency is present for countries",
410+
currency: "EUR",
411+
expectedError: nil,
412+
expectedCountry: 34,
413+
},
414+
{
415+
name: "Find countries by unknown country code should return error when searching countries",
416+
currency: "ERT",
417+
expectedError: fmt.Errorf("gountries error. Could not find countries with currency name: ERT"),
418+
expectedCountry: 0,
419+
},
420+
{
421+
name: "Find countries by invalid currency length code should return error when searching countries",
422+
currency: "CNYE",
423+
expectedError: fmt.Errorf("gountries error. Invalid currency format: CNYE"),
424+
expectedCountry: 0,
425+
},
426+
}
427+
for _, test := range tests {
428+
t.Run(test.name, func(t *testing.T) {
429+
actualCountry, actualError := query.FindCountriesByCurrency(test.currency)
430+
if !(reflect.DeepEqual(test.expectedCountry, len(actualCountry)) &&
431+
reflect.DeepEqual(test.expectedError, actualError)) {
432+
t.Fail()
433+
}
434+
})
435+
}
436+
}

0 commit comments

Comments
 (0)