Skip to content

Commit

Permalink
Merge pull request #161 from ctreminiom/feature/160
Browse files Browse the repository at this point in the history
✨ Implemented the Workflow.Status.Bulk method
  • Loading branch information
ctreminiom authored Nov 8, 2022
2 parents b104580 + 8b1ae44 commit 632ebbf
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
27 changes: 27 additions & 0 deletions jira/internal/workflow_status_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,38 @@ func (w *WorkflowStatusService) Search(ctx context.Context, options *model.Workf
return w.internalClient.Search(ctx, options, startAt, maxResults)
}

// Bulk returns a list of all statuses associated with active workflows.
//
// GET /rest/api/{2-3}/status
//
// https://docs.go-atlassian.io/jira-software-cloud/workflow/status#bulk-workflow-statuses
func (w *WorkflowStatusService) Bulk(ctx context.Context) ([]*model.StatusDetailScheme, *model.ResponseScheme, error) {
return w.internalClient.Bulk(ctx)
}

type internalWorkflowStatusImpl struct {
c service.Client
version string
}

func (i *internalWorkflowStatusImpl) Bulk(ctx context.Context) ([]*model.StatusDetailScheme, *model.ResponseScheme, error) {

endpoint := fmt.Sprintf("/rest/api/%v/status", i.version)

request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, nil, err
}

var statuses []*model.StatusDetailScheme
response, err := i.c.Call(request, &statuses)
if err != nil {
return nil, response, err
}

return statuses, response, nil
}

func (i *internalWorkflowStatusImpl) Gets(ctx context.Context, ids, expand []string) ([]*model.WorkflowStatusDetailScheme, *model.ResponseScheme, error) {

var endpoint strings.Builder
Expand Down
130 changes: 130 additions & 0 deletions jira/internal/workflow_status_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,133 @@ func Test_internalWorkflowStatusImpl_Search(t *testing.T) {
})
}
}

func Test_internalWorkflowStatusImpl_Bulk(t *testing.T) {

type fields struct {
c service.Client
version string
}

type args struct {
ctx context.Context
}

testCases := []struct {
name string
fields fields
args args
on func(*fields)
wantErr bool
Err error
}{
{
name: "when the api version is v3",
fields: fields{version: "3"},
args: args{
ctx: context.TODO(),
},
on: func(fields *fields) {

client := mocks.NewClient(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"/rest/api/3/status",
nil).
Return(&http.Request{}, nil)

client.On("Call",
&http.Request{},
mock.Anything).
Return(&model.ResponseScheme{}, nil)

fields.c = client
},
wantErr: false,
Err: nil,
},

{
name: "when the api version is v2",
fields: fields{version: "2"},
args: args{
ctx: context.TODO(),
},
on: func(fields *fields) {

client := mocks.NewClient(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"/rest/api/2/status",
nil).
Return(&http.Request{}, nil)

client.On("Call",
&http.Request{},
mock.Anything).
Return(&model.ResponseScheme{}, nil)

fields.c = client
},
wantErr: false,
Err: nil,
},

{
name: "when the http request cannot be created",
fields: fields{version: "3"},
args: args{
ctx: context.TODO(),
},
on: func(fields *fields) {

client := mocks.NewClient(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"/rest/api/3/status",
nil).
Return(&http.Request{}, errors.New("error, unable to create the http request"))

fields.c = client
},
wantErr: true,
Err: errors.New("error, unable to create the http request"),
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {

if testCase.on != nil {
testCase.on(&testCase.fields)
}

newService, err := NewWorkflowStatusService(testCase.fields.c, testCase.fields.version)
assert.NoError(t, err)

gotResult, gotResponse, err := newService.Bulk(testCase.args.ctx)

if testCase.wantErr {

if err != nil {
t.Logf("error returned: %v", err.Error())
}

assert.EqualError(t, err, testCase.Err.Error())

} else {

assert.NoError(t, err)
assert.NotEqual(t, gotResponse, nil)
assert.NotEqual(t, gotResult, nil)
}

})
}
}
10 changes: 10 additions & 0 deletions pkg/infra/models/jira_workflow_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ type WorkflowStatusSearchParams struct {
StatusCategory string
Expand []string
}

type StatusDetailScheme struct {
Self string `json:"self,omitempty"`
Description string `json:"description,omitempty"`
IconURL string `json:"iconUrl,omitempty"`
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
StatusCategory *StatusCategoryScheme `json:"statusCategory,omitempty"`
Scope *WorkflowStatusScopeScheme `json:"scope,omitempty"`
}
7 changes: 7 additions & 0 deletions service/jira/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,11 @@ type WorkflowStatusConnector interface {
// https://docs.go-atlassian.io/jira-software-cloud/workflow/status#search-workflow-statuses
Search(ctx context.Context, options *model.WorkflowStatusSearchParams, startAt, maxResults int) (*model.WorkflowStatusDetailPageScheme,
*model.ResponseScheme, error)

// Bulk returns a list of all statuses associated with active workflows.
//
// GET /rest/api/{2-3}/status
//
// https://docs.go-atlassian.io/jira-software-cloud/workflow/status#bulk-workflow-statuses
Bulk(ctx context.Context) ([]*model.StatusDetailScheme, *model.ResponseScheme, error)
}

0 comments on commit 632ebbf

Please sign in to comment.