From 9126a4f1dcdae8997ebe4c7074e8e9fa49ce077d Mon Sep 17 00:00:00 2001 From: MrShtein Date: Sat, 11 May 2024 18:26:55 +0300 Subject: [PATCH] test: Added test for addressByCoordinates method --- dadata_test.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/dadata_test.go b/dadata_test.go index 886b0dc..21ad5c9 100644 --- a/dadata_test.go +++ b/dadata_test.go @@ -6,8 +6,10 @@ import ( "context" "fmt" "os" + "strconv" "testing" + "github.com/ekomobile/dadata/v2/api/geolocate" "github.com/stretchr/testify/suite" "github.com/ekomobile/dadata/v2/api/suggest" @@ -21,6 +23,10 @@ type ( ApiCleanIntegrationTest struct { suite.Suite } + + ApiGeolocateIntegrationTest struct { + suite.Suite + } ) func (s *ApiSuggestIntegrationTest) SetupSuite() { @@ -35,6 +41,12 @@ func (s *ApiCleanIntegrationTest) SetupSuite() { } } +func (s *ApiGeolocateIntegrationTest) SetupSuite() { + if _, ok := os.LookupEnv("DADATA_API_KEY"); !ok { + s.Suite.T().Skip("no api keys in env") + } +} + func TestSuggestApiIntegration(t *testing.T) { suite.Run(t, &ApiSuggestIntegrationTest{}) } @@ -43,6 +55,10 @@ func TestCleanApiIntegration(t *testing.T) { suite.Run(t, &ApiCleanIntegrationTest{}) } +func TestGeolocationApiIntegration(t *testing.T) { + suite.Run(t, &ApiGeolocateIntegrationTest{}) +} + func (s *ApiSuggestIntegrationTest) TestAddress() { api := NewSuggestApi() params := suggest.RequestParams{ @@ -288,6 +304,106 @@ func (s *ApiCleanIntegrationTest) TestPassport() { s.Len(res, 1) } +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithoutLongitude() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{ + Lat: "55.878", + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.Empty(res) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithoutLatitude() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{ + Lon: "37.653", + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.Empty(res) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithEmptyBody() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{} + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.Empty(res) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithLanguageParamRU() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{ + Lat: "55.878", + Lon: "37.653", + Language: "RU", + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.NotEmpty(res) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithLanguageParamEN() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{ + Lat: "55.878", + Lon: "37.653", + Language: "EN", + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.NotEmpty(res) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithCountTwo() { + api := NewGeolocateApi() + reqElementCount := 2 + + params := geolocate.RequestParams{ + Lat: "55.878", + Lon: "37.653", + Language: "EN", + Count: strconv.Itoa(reqElementCount), + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.Len(res, 2) +} + +func (s *ApiGeolocateIntegrationTest) TestAddressByCoordinatesWithRadius() { + api := NewGeolocateApi() + + params := geolocate.RequestParams{ + Lat: "55.878", + Lon: "37.653", + Language: "EN", + RadiusMeters: "100", + } + + res, err := api.AddressByCoordinates(context.Background(), ¶ms) + + s.NoError(err) + s.NotEmpty(res) +} + func ExampleNewSuggestApi() { api := NewSuggestApi()