Skip to content

Commit

Permalink
Merge pull request #127 from ctreminiom/feature/screen-scheme-expand-bug
Browse files Browse the repository at this point in the history
🔥 Added the ability to expand the issuetypesscreenschemes associ…
  • Loading branch information
ctreminiom authored Jun 29, 2022
2 parents 8819cfe + 6fea3a1 commit 9baec39
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 69 deletions.
2 changes: 1 addition & 1 deletion jira/v2/issueTypeScreenScheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IssueTypeScreenSchemeService struct{ client *Client }
// Gets returns a paginated list of issue type screen schemes.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/types/screen-scheme#get-issue-type-screen-schemes
// Atlassian Docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-type-screen-schemes/#api-rest-api-2-issuetypescreenscheme-get
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.IssueTypeScreenSchemeParamsScheme, startAt, maxResults int) (
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.ScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.IssueTypeScreenSchemePageScheme, response *ResponseScheme, err error) {

params := url.Values{}
Expand Down
14 changes: 7 additions & 7 deletions jira/v2/issueTypeScreenScheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

testCases := []struct {
name string
options *models.IssueTypeScreenSchemeParamsScheme
options *models.ScreenSchemeParamsScheme
startAt int
maxResults int
mockFile string
Expand All @@ -785,7 +785,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
}{
{
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -803,7 +803,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -821,7 +821,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -839,7 +839,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -857,7 +857,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheContextIsNil",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -875,7 +875,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand Down
22 changes: 19 additions & 3 deletions jira/v2/screenSchemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)

type ScreenSchemeService struct{ client *Client }
Expand All @@ -15,15 +16,30 @@ type ScreenSchemeService struct{ client *Client }
// Only screen schemes used in classic projects are returned.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/screens/schemes#get-screen-schemes
// Atlassian Docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-screen-schemes/#api-rest-api-2-screenscheme-get
func (s *ScreenSchemeService) Gets(ctx context.Context, screenSchemeIDs []int, startAt, maxResults int) (
func (s *ScreenSchemeService) Gets(ctx context.Context, options *models.ScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.ScreenSchemePageScheme, response *ResponseScheme, err error) {

params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))

for _, schemeScheme := range screenSchemeIDs {
params.Add("id", strconv.Itoa(schemeScheme))
if options != nil {

for _, id := range options.IDs {
params.Add("id", strconv.Itoa(id))
}

if options.QueryString != "" {
params.Add("queryString", options.QueryString)
}

if options.OrderBy != "orderBy" {
params.Add("", options.OrderBy)
}

if len(options.Expand) != 0 {
params.Add("expand", strings.Join(options.Expand, ","))
}
}

var endpoint = fmt.Sprintf("rest/api/2/screenscheme?%v", params.Encode())
Expand Down
70 changes: 50 additions & 20 deletions jira/v2/screenSchemes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestScreenSchemeService_Gets(t *testing.T) {

testCases := []struct {
name string
screenSchemeIDs []int
options *models.ScreenSchemeParamsScheme
startAt, maxResults int
mockFile string
wantHTTPMethod string
Expand All @@ -341,78 +341,108 @@ func TestScreenSchemeService_Gets(t *testing.T) {
wantErr bool
}{
{
name: "GetScreenSchemesWhenTheParamsAreCorrect",
screenSchemeIDs: []int{1000, 1001, 1002, 1002},
name: "GetScreenSchemesWhenTheParamsAreCorrect",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/screenscheme?id=1000&id=1001&id=1002&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetScreenSchemesWhenTheScreenSchemeIDsIsNil",
screenSchemeIDs: nil,
name: "GetScreenSchemesWhenTheScreenSchemeIDsIsNil",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/screenscheme?maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetScreenSchemesWhenTheContextIsNil",
screenSchemeIDs: []int{1000, 1001, 1002, 1002},
name: "GetScreenSchemesWhenTheContextIsNil",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/screenscheme?id=1000&id=1001&id=1002&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: nil,
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetScreenSchemesWhenTheRequestMethodIsIncorrect",
screenSchemeIDs: []int{1000, 1001, 1002, 1002},
name: "GetScreenSchemesWhenTheRequestMethodIsIncorrect",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-screen-schemes.json",
wantHTTPMethod: http.MethodPost,
endpoint: "/rest/api/2/screenscheme?id=1000&id=1001&id=1002&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetScreenSchemesWhenTheStatusCodeIsIncorrect",
screenSchemeIDs: []int{1000, 1001, 1002, 1002},
name: "GetScreenSchemesWhenTheStatusCodeIsIncorrect",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/screenscheme?id=1000&id=1001&id=1002&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusBadRequest,
wantErr: true,
},

{
name: "GetScreenSchemesWhenTheResponseBodyHasADifferentFormat",
screenSchemeIDs: []int{1000, 1001, 1002, 1002},
name: "GetScreenSchemesWhenTheResponseBodyHasADifferentFormat",
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002, 1002},
QueryString: "query-string",
OrderBy: "name",
Expand: []string{"issueTypeScreenSchemes"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/empty_json.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/screenscheme?id=1000&id=1001&id=1002&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/screenscheme?=name&expand=issueTypeScreenSchemes&id=1000&id=1001&id=1002&id=1002&maxResults=50&queryString=query-string&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
Expand Down Expand Up @@ -446,7 +476,7 @@ func TestScreenSchemeService_Gets(t *testing.T) {

i := &ScreenSchemeService{client: mockClient}

gotResult, gotResponse, err := i.Gets(testCase.context, testCase.screenSchemeIDs, testCase.startAt,
gotResult, gotResponse, err := i.Gets(testCase.context, testCase.options, testCase.startAt,
testCase.maxResults)

if testCase.wantErr {
Expand Down
2 changes: 1 addition & 1 deletion jira/v3/issueTypeScreenScheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IssueTypeScreenSchemeService struct{ client *Client }
// Gets returns a paginated list of issue type screen schemes.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/types/screen-scheme#get-issue-type-screen-schemes
// Atlassian Docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-type-screen-schemes/#api-rest-api-3-issuetypescreenscheme-get
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.IssueTypeScreenSchemeParamsScheme, startAt, maxResults int) (
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.ScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.IssueTypeScreenSchemePageScheme, response *ResponseScheme, err error) {

params := url.Values{}
Expand Down
14 changes: 7 additions & 7 deletions jira/v3/issueTypeScreenScheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

testCases := []struct {
name string
options *models.IssueTypeScreenSchemeParamsScheme
options *models.ScreenSchemeParamsScheme
startAt int
maxResults int
mockFile string
Expand All @@ -785,7 +785,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
}{
{
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -803,7 +803,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -821,7 +821,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -839,7 +839,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -857,7 +857,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheContextIsNil",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand All @@ -875,7 +875,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

{
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
options: &models.IssueTypeScreenSchemeParamsScheme{
options: &models.ScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand Down
22 changes: 19 additions & 3 deletions jira/v3/screenSchemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)

type ScreenSchemeService struct{ client *Client }
Expand All @@ -15,15 +16,30 @@ type ScreenSchemeService struct{ client *Client }
// Only screen schemes used in classic projects are returned.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/screens/schemes#get-screen-schemes
// Atlassian Docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-screen-schemes/#api-rest-api-3-screenscheme-get
func (s *ScreenSchemeService) Gets(ctx context.Context, screenSchemeIDs []int, startAt, maxResults int) (
func (s *ScreenSchemeService) Gets(ctx context.Context, options *models.ScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.ScreenSchemePageScheme, response *ResponseScheme, err error) {

params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
params.Add("maxResults", strconv.Itoa(maxResults))

for _, schemeScheme := range screenSchemeIDs {
params.Add("id", strconv.Itoa(schemeScheme))
if options != nil {

for _, id := range options.IDs {
params.Add("id", strconv.Itoa(id))
}

if options.QueryString != "" {
params.Add("queryString", options.QueryString)
}

if options.OrderBy != "orderBy" {
params.Add("", options.OrderBy)
}

if len(options.Expand) != 0 {
params.Add("expand", strings.Join(options.Expand, ","))
}
}

var endpoint = fmt.Sprintf("rest/api/3/screenscheme?%v", params.Encode())
Expand Down
Loading

0 comments on commit 9baec39

Please sign in to comment.