Merge pull request #23 from ekomobile/clean_endpoint
Fixed clean API endpoint. Added cleaner live API tests.
This commit is contained in:
commit
03fde44917
10
dadata.go
10
dadata.go
@ -15,11 +15,14 @@ const (
|
|||||||
EndpointURL = "https://dadata.ru/api/v2/"
|
EndpointURL = "https://dadata.ru/api/v2/"
|
||||||
// EndpointURLSuggest is a suggestion API endpoint.
|
// EndpointURLSuggest is a suggestion API endpoint.
|
||||||
EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
|
EndpointURLSuggest = "https://suggestions.dadata.ru/suggestions/api/4_1/rs/"
|
||||||
|
// EndpointURLClean is a cleaner API endpoint.
|
||||||
|
EndpointURLClean = "https://cleaner.dadata.ru/api/v1/"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
endpointURL *url.URL
|
endpointURL *url.URL
|
||||||
endpointURLSuggest *url.URL
|
endpointURLSuggest *url.URL
|
||||||
|
endpointURLClean *url.URL
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -34,12 +37,17 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endpointURLClean, err = url.Parse(EndpointURLClean)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCleanApi provides "clean" API.
|
// NewCleanApi provides "clean" API.
|
||||||
func NewCleanApi(opts ...client.Option) *clean.Api {
|
func NewCleanApi(opts ...client.Option) *clean.Api {
|
||||||
return &clean.Api{
|
return &clean.Api{
|
||||||
Client: client.NewClient(endpointURL, opts...),
|
Client: client.NewClient(endpointURLClean, opts...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Live API tests.
|
||||||
|
// To run API test pass `DADATA_API_KEY` and `DADATA_SECRET_KEY` environment variables with your values.
|
||||||
package dadata
|
package dadata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -15,6 +17,10 @@ type (
|
|||||||
ApiSuggestIntegrationTest struct {
|
ApiSuggestIntegrationTest struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApiCleanIntegrationTest struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *ApiSuggestIntegrationTest) SetupSuite() {
|
func (s *ApiSuggestIntegrationTest) SetupSuite() {
|
||||||
@ -23,6 +29,20 @@ func (s *ApiSuggestIntegrationTest) SetupSuite() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) 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{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCleanApiIntegration(t *testing.T) {
|
||||||
|
suite.Run(t, &ApiCleanIntegrationTest{})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ApiSuggestIntegrationTest) TestAddress() {
|
func (s *ApiSuggestIntegrationTest) TestAddress() {
|
||||||
api := NewSuggestApi()
|
api := NewSuggestApi()
|
||||||
params := suggest.RequestParams{
|
params := suggest.RequestParams{
|
||||||
@ -158,8 +178,60 @@ func (s *ApiSuggestIntegrationTest) TestFMSUnit() {
|
|||||||
s.NotEmpty(res)
|
s.NotEmpty(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSuggestApiIntegration(t *testing.T) {
|
func (s *ApiCleanIntegrationTest) TestAddress() {
|
||||||
suite.Run(t, &ApiSuggestIntegrationTest{})
|
api := NewCleanApi()
|
||||||
|
res, err := api.Address(context.Background(), "мск сухонска 11/-89")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestPhone() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Phone(context.Background(), "+79851234567")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestName() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Name(context.Background(), "Срегей владимерович иванов")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestEmail() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Email(context.Background(), "serega@yandex/ru")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestBirthday() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Birthday(context.Background(), "12 12 12")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestVehicle() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Vehicle(context.Background(), "форд фокус")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiCleanIntegrationTest) TestPassport() {
|
||||||
|
api := NewCleanApi()
|
||||||
|
res, err := api.Passport(context.Background(), "4509 235857")
|
||||||
|
s.NoError(err)
|
||||||
|
s.NotEmpty(res)
|
||||||
|
s.Len(res, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleNewSuggestApi() {
|
func ExampleNewSuggestApi() {
|
||||||
|
Loading…
Reference in New Issue
Block a user