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

Allow API endpoints to determine default boolean option values #12

Merged
Merged
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
2 changes: 1 addition & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Filter struct {

// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
type GetMyFiltersQueryOptions struct {
IncludeFavourites bool `url:"includeFavourites,omitempty"`
IncludeFavourites *bool `url:"includeFavourites,omitempty"`
Expand string `url:"expand,omitempty"`
}

Expand Down
14 changes: 7 additions & 7 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type IssueService struct {

// UpdateQueryOptions specifies the optional parameters to the Edit issue
type UpdateQueryOptions struct {
NotifyUsers bool `url:"notifyUsers,omitempty"`
OverrideScreenSecurity bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
NotifyUsers *bool `url:"notifyUsers,omitempty"`
OverrideScreenSecurity *bool `url:"overrideScreenSecurity,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// Issue represents a Jira issue.
Expand Down Expand Up @@ -544,8 +544,8 @@ type GetQueryOptions struct {
// Properties is the list of properties to return for the issue. By default no properties are returned.
Properties string `url:"properties,omitempty"`
// FieldsByKeys if true then fields in issues will be referenced by keys instead of ids
FieldsByKeys bool `url:"fieldsByKeys,omitempty"`
UpdateHistory bool `url:"updateHistory,omitempty"`
FieldsByKeys *bool `url:"fieldsByKeys,omitempty"`
UpdateHistory *bool `url:"updateHistory,omitempty"`
ProjectKeys string `url:"projectKeys,omitempty"`
}

Expand All @@ -558,12 +558,12 @@ type GetWorklogsQueryOptions struct {
}

type AddWorklogQueryOptions struct {
NotifyUsers bool `url:"notifyUsers,omitempty"`
NotifyUsers *bool `url:"notifyUsers,omitempty"`
AdjustEstimate string `url:"adjustEstimate,omitempty"`
NewEstimate string `url:"newEstimate,omitempty"`
ReduceBy string `url:"reduceBy,omitempty"`
Expand string `url:"expand,omitempty"`
OverrideEditableFlag bool `url:"overrideEditableFlag,omitempty"`
OverrideEditableFlag *bool `url:"overrideEditableFlag,omitempty"`
}

// CustomFields represents custom fields of Jira
Expand Down
45 changes: 45 additions & 0 deletions jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,51 @@ func TestClient_NewRequest_EmptyBody(t *testing.T) {
}
}

// Tests that addOptions correctly serialises *bools, which are used to convey the desired value of
// options that default to true on the API endpoint if a value is not specified in the request:
//
// | Option value | Expected outcome |
// | ------------ | ------------------------------ |
// | *true | opt=true in request |
// | *false | opt=false in request |
// | nil | Determined by the API endpoint |
func Test_addOptions_Bool_Pointer(t *testing.T) {
apiEndpoint := "rest/api/2/issue/123"

for _, test := range []struct {
Description string
Opts *UpdateQueryOptions
Expected string
}{
{
Description: "*bool implicitly nil",
Opts: &UpdateQueryOptions{},
Expected: "",
},
{
Description: "*bool explicitly nil",
Opts: &UpdateQueryOptions{NotifyUsers: nil},
Expected: "",
},
{
Description: "*bool explicitly true",
Opts: &UpdateQueryOptions{NotifyUsers: Bool(true)},
Expected: "?notifyUsers=true",
},
{
Description: "*bool explicitly false",
Opts: &UpdateQueryOptions{NotifyUsers: Bool(false)},
Expected: "?notifyUsers=false",
},
} {
t.Run(test.Description, func(t *testing.T) {
actual, err := addOptions(apiEndpoint, test.Opts)
assert.NoError(t, err)
assert.Equal(t, apiEndpoint + test.Expected, actual)
})
}
}

func TestClient_NewMultiPartRequest(t *testing.T) {
c, err := NewClient(nil, testJiraInstanceURL)
if err != nil {
Expand Down
Loading