Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 ChangeOrderRequest: Allow zero as targetIndex #92

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,18 @@ func TestDeletePolicy_Validate(t *testing.T) {
}

func TestChangeOrder_Validate(t *testing.T) {
targetIndex := -1
request := &ChangeOrderRequest{
Id: "asd",
TeamId: "asd",
Type: NotificationPolicy,
TargetIndex: -1,
TargetIndex: &targetIndex,
}
err := request.Validate()
assert.Equal(t, "target index should be at least 0", err.Error())

request.TargetIndex = 0
targetIndex = 0
request.TargetIndex = &targetIndex
err = request.Validate()
assert.Nil(t, err)
}
Expand Down
4 changes: 2 additions & 2 deletions policy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ type ChangeOrderRequest struct {
Id string `json:"id,omitempty"`
TeamId string
Type PolicyType
TargetIndex int `json:"targetIndex,omitempty"`
TargetIndex *int `json:"targetIndex,omitempty"`
}

func (r *ChangeOrderRequest) Validate() error {
Expand All @@ -451,7 +451,7 @@ func (r *ChangeOrderRequest) Validate() error {
if err != nil {
return err
}
if r.TargetIndex < 0 {
if *r.TargetIndex < 0 {
return errors.New("target index should be at least 0")
}
return nil
Expand Down