Skip to content

Commit

Permalink
Merge pull request #130 from ctreminiom/feature/workflow-options
Browse files Browse the repository at this point in the history
🚧 Mapped the Jira.Workflow.Search options
  • Loading branch information
ctreminiom authored Jul 4, 2022
2 parents 749c215 + c4e3a06 commit 0e44336
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 150 deletions.
26 changes: 20 additions & 6 deletions jira/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,33 @@ func (w *WorkflowService) Create(ctx context.Context, payload *models.WorkflowPa
// Gets returns a paginated list of published classic workflows.
// When workflow names are specified, details of those workflows are returned.
// Otherwise, all published classic workflows are returned.
func (w *WorkflowService) Gets(ctx context.Context, workflowNames, expand []string, startAt, maxResults int) (result *models.WorkflowPageScheme,
func (w *WorkflowService) Gets(ctx context.Context, options *models.WorkflowSearchOptions, startAt, maxResults int) (result *models.WorkflowPageScheme,
response *ResponseScheme, err error) {

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

for _, workflowName := range workflowNames {
params.Add("workflowName", workflowName)
}
if options != nil {

for _, name := range options.WorkflowNames {
params.Add("workflowName", name)
}

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

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

params.Add("isActive", fmt.Sprintf("%T", options.IsActive))

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

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

var endpoint = fmt.Sprintf("/rest/api/2/workflow/search?%v", params.Encode())
Expand Down
151 changes: 82 additions & 69 deletions jira/v2/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,109 +139,124 @@ func TestWorkflowService_Delete(t *testing.T) {
func TestWorkflowService_Gets(t *testing.T) {

testCases := []struct {
name string
startAt, maxResults int
mockFile string
workflowNames, expand []string
wantHTTPMethod string
endpoint string
context context.Context
wantHTTPCodeReturn int
wantErr bool
name string
startAt, maxResults int
mockFile string
options *models.WorkflowSearchOptions
wantHTTPMethod string
endpoint string
context context.Context
wantHTTPCodeReturn int
wantErr bool
}{
{
name: "GetsWorkflowsWheTheParametersAreCorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheParametersAreCorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetsWorkflowsWheTheContextIsNotSet",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheContextIsNotSet",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: nil,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetsWorkflowsWheTheRequestMethodIsIncorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheRequestMethodIsIncorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodHead,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
},

{
name: "GetsWorkflowsWheTheStatusCodeIsIncorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheStatusCodeIsIncorrect",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusBadRequest,
wantErr: true,
},

{
name: "GetsWorkflowsWheTheExpandsAreNotSet",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: nil,
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetsWorkflowsWheTheWorkflowNamesAreNotSet",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
workflowNames: nil,
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheExpandsAreNotSet",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/get-workflows.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0",
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: false,
},

{
name: "GetsWorkflowsWheTheResponseBodyIsEmpty",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/empty_json.json",
workflowNames: []string{"workflow name 1", "workflow name 2"},
expand: []string{"transitions", "transitions.rules", "default"},
name: "GetsWorkflowsWheTheResponseBodyIsEmpty",
startAt: 0,
maxResults: 50,
mockFile: "../v3/mocks/empty_json.json",
options: &models.WorkflowSearchOptions{
QueryString: "name",
WorkflowNames: []string{"workflow name 1", "workflow name 2"},
OrderBy: "name",
IsActive: true,
Expand: []string{"transitions", "transitions.rules", "default"},
},
wantHTTPMethod: http.MethodGet,
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&maxResults=50&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
endpoint: "/rest/api/2/workflow/search?expand=transitions%2Ctransitions.rules%2Cdefault&isActive=bool&maxResults=50&orderBy=name&queryString=name&startAt=0&workflowName=workflow+name+1&workflowName=workflow+name+2",
context: context.Background(),
wantHTTPCodeReturn: http.StatusOK,
wantErr: true,
Expand Down Expand Up @@ -275,9 +290,7 @@ func TestWorkflowService_Gets(t *testing.T) {

i := &WorkflowService{client: mockClient}

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

if testCase.wantErr {

Expand Down
26 changes: 20 additions & 6 deletions jira/v3/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,33 @@ func (w *WorkflowService) Create(ctx context.Context, payload *models.WorkflowPa
// When workflow names are specified, details of those workflows are returned.
// Otherwise, all published classic workflows are returned.
// Atlassian Docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-workflows/#api-rest-api-3-workflow-search-get
func (w *WorkflowService) Gets(ctx context.Context, workflowNames, expand []string, startAt, maxResults int) (result *models.WorkflowPageScheme,
func (w *WorkflowService) Gets(ctx context.Context, options *models.WorkflowSearchOptions, startAt, maxResults int) (result *models.WorkflowPageScheme,
response *ResponseScheme, err error) {

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

for _, workflowName := range workflowNames {
params.Add("workflowName", workflowName)
}
if options != nil {

for _, name := range options.WorkflowNames {
params.Add("workflowName", name)
}

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

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

params.Add("isActive", fmt.Sprintf("%T", options.IsActive))

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

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

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

0 comments on commit 0e44336

Please sign in to comment.