test: Added test for addressByCoordinates method
This commit is contained in:
parent
bba41d685e
commit
9126a4f1dc
116
dadata_test.go
116
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user