Skip to content

Commit

Permalink
Merge pull request #28 from MashinaMashina/master
Browse files Browse the repository at this point in the history
Organization status filter
  • Loading branch information
turboezh authored Oct 25, 2024
2 parents 94fa3d3 + c63e10b commit 17d1af4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/suggest/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ type (
KPP *string `json:"kpp,omitempty"`
Type *PartyType `json:"type,omitempty"`
BranchType *PartyBranchType `json:"branch_type,omitempty"`
Status []PartyStatus `json:"status,omitempty"`
}

PartyType string
PartyBranchType string
PartyStatus string
)

const (
Expand All @@ -23,6 +25,10 @@ const (

PartyBranchTypeMain PartyBranchType = "MAIN"
PartyBranchTypeBranch PartyBranchType = "BRANCH"

PartyStatusActive PartyStatus = "ACTIVE"
PartyStatusLiquidating PartyStatus = "LIQUIDATING"
PartyStatusLiquidated PartyStatus = "LIQUIDATED"
)

func NewPartyByIDParams(query string) *PartyByIDParams {
Expand Down Expand Up @@ -56,7 +62,13 @@ func (o *PartyByIDParams) SetBranchType(t PartyBranchType) *PartyByIDParams {
return o
}

func (o *PartyByIDParams) SetStatus(s ...PartyStatus) *PartyByIDParams {
o.Status = s
return o
}

// Party try to return suggest parties by params
// https://dadata.ru/api/suggest/party/
func (a *Api) Party(ctx context.Context, params *RequestParams) (ret []*PartySuggestion, err error) {
var result = &PartyResponse{}

Expand Down
52 changes: 52 additions & 0 deletions dadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,58 @@ func (s *ApiSuggestIntegrationTest) TestPartyByIdWithBranchType() {
s.Equal(query, res[0].Data.Inn)
}

func (s *ApiSuggestIntegrationTest) TestPartyByIdWithStatusActive() {
api := NewSuggestApi()

query := "7707083893"

params := suggest.NewPartyByIDParams(query).
SetBranchType(suggest.PartyBranchTypeMain).
SetType(suggest.PartyTypeLegal).
SetStatus(suggest.PartyStatusActive)

res, err := api.PartyByID(context.Background(), params)

s.NoError(err)
s.NotEmpty(res)
s.Equal(query, res[0].Data.Inn)
s.Equal(string(suggest.PartyStatusActive), res[0].Data.State.Status)
}

func (s *ApiSuggestIntegrationTest) TestPartyByIdWithStatusLiquidatedAndActive() {
api := NewSuggestApi()

query := "7707083893"

params := suggest.NewPartyByIDParams(query).
SetBranchType(suggest.PartyBranchTypeMain).
SetType(suggest.PartyTypeLegal).
SetStatus(suggest.PartyStatusLiquidated, suggest.PartyStatusActive)

res, err := api.PartyByID(context.Background(), params)

s.NoError(err)
s.NotEmpty(res)
s.Equal(query, res[0].Data.Inn)
s.Equal(string(suggest.PartyStatusActive), res[0].Data.State.Status)
}

func (s *ApiSuggestIntegrationTest) TestPartyByIdWithStatusLiquidatedNegative() {
api := NewSuggestApi()

query := "7707083893"

params := suggest.NewPartyByIDParams(query).
SetBranchType(suggest.PartyBranchTypeMain).
SetType(suggest.PartyTypeLegal).
SetStatus(suggest.PartyStatusLiquidated)

res, err := api.PartyByID(context.Background(), params)

s.NoError(err)
s.Len(res, 0)
}

func (s *ApiSuggestIntegrationTest) TestCountry() {
api := NewSuggestApi()
params := suggest.RequestParams{
Expand Down

0 comments on commit 17d1af4

Please sign in to comment.