Skip to content

Commit

Permalink
🔥 Added the ability to expand the projects associated with a issue ty…
Browse files Browse the repository at this point in the history
…pe screen scheme.
  • Loading branch information
ctreminiom committed Jun 27, 2022
1 parent 287f64f commit 2bd33e4
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 73 deletions.
22 changes: 19 additions & 3 deletions jira/v2/issueTypeScreenScheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)

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, ids []int, startAt, maxResults int) (
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.IssueTypeScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.IssueTypeScreenSchemePageScheme, response *ResponseScheme, err error) {

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

for _, id := range ids {
params.Add("id", strconv.Itoa(id))
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/issuetypescreenscheme?%v", params.Encode())
Expand Down
75 changes: 46 additions & 29 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
ids []int
options *models.IssueTypeScreenSchemeParamsScheme
startAt int
maxResults int
mockFile string
Expand All @@ -784,47 +784,49 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
wantErr bool
}{
{
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
ids: []int{1000, 1001, 1002},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetIssueTypeSchemesWhenTheIdsAreNotSet",
ids: nil,
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/issuetypescreenscheme?maxResults=50&startAt=0",
endpoint: "/rest/api/2/issuetypescreenscheme?=id&expand=projects&id=1000&id=1001&id=1002&maxResults=50&queryString=DUMMY&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/issuetypescreenschemes?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/2/issuetypescreesnschemes?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
Expand All @@ -836,8 +838,13 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
Expand All @@ -849,8 +856,13 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheContextIsNil",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheContextIsNil",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
Expand All @@ -862,8 +874,13 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/empty_json.json",
Expand Down Expand Up @@ -902,7 +919,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

i := &IssueTypeScreenSchemeService{client: mockClient}

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

if testCase.wantErr {

Expand Down
22 changes: 19 additions & 3 deletions jira/v3/issueTypeScreenScheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
)

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, ids []int, startAt, maxResults int) (
func (i *IssueTypeScreenSchemeService) Gets(ctx context.Context, options *models.IssueTypeScreenSchemeParamsScheme, startAt, maxResults int) (
result *models.IssueTypeScreenSchemePageScheme, response *ResponseScheme, err error) {

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

for _, id := range ids {
params.Add("id", strconv.Itoa(id))
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/issuetypescreenscheme?%v", params.Encode())
Expand Down
87 changes: 52 additions & 35 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
ids []int
options *models.IssueTypeScreenSchemeParamsScheme
startAt int
maxResults int
mockFile string
Expand All @@ -784,50 +784,52 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
wantErr bool
}{
{
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
ids: []int{1000, 1001, 1002},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetIssueTypeSchemesWhenTheIdsAreNotSet",
ids: nil,
name: "GetIssueTypeSchemesWhenTheParametersAreCorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenscheme?maxResults=50&startAt=0",
endpoint: "/rest/api/3/issuetypescreenscheme?=id&expand=projects&id=1000&id=1001&id=1002&maxResults=50&queryString=DUMMY&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheEndpointIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenschemes?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
endpoint: "/rest/api/3/issuetypescreesnschemes?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheRequestMethodIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodPost,
endpoint: "/rest/api/3/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
Expand All @@ -836,11 +838,16 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheStatusCodeIsIncorrect",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
Expand All @@ -849,11 +856,16 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheContextIsNil",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheContextIsNil",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/get-issue-type-screen-schemes.json",
mockFile: "../v3/mocks/get-issue-type-screen-schemes.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: nil,
Expand All @@ -862,11 +874,16 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {
},

{
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
ids: []int{1000, 1001, 1002},
name: "GetIssueTypeSchemesWhenTheResponseBodyHasADifferentFormat",
options: &models.IssueTypeScreenSchemeParamsScheme{
IDs: []int{1000, 1001, 1002},
QueryString: "DUMMY",
OrderBy: "id",
Expand: []string{"projects"},
},
startAt: 0,
maxResults: 50,
mockFile: "./mocks/empty_json.json",
mockFile: "../v3/mocks/empty_json.json",
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/3/issuetypescreenscheme?id=1000&id=1001&id=1002&maxResults=50&startAt=0",
context: context.Background(),
Expand Down Expand Up @@ -902,7 +919,7 @@ func TestIssueTypeScreenSchemeService_Gets(t *testing.T) {

i := &IssueTypeScreenSchemeService{client: mockClient}

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

if testCase.wantErr {

Expand Down
Loading

0 comments on commit 2bd33e4

Please sign in to comment.