Repository: ctreminiom/go-atlassian
Pull request #193 (2023-05-05 18:10:36)

:sparkles: Added the ability to manipulate the Workflow Scheme issue …
…types


Patch:
diff --git a/jira/internal/workflow_scheme_impl.go b/jira/internal/workflow_scheme_impl.go
index 318d760..75d782b 100644
--- a/jira/internal/workflow_scheme_impl.go
+++ b/jira/internal/workflow_scheme_impl.go
@@ -12,19 +12,17 @@ import (
 	"strings"
 )
 
-func NewWorkflowSchemeService(client service.Client, version string) (*WorkflowSchemeService, error) {
-
-	if version == "" {
-		return nil, model.ErrNoVersionProvided
-	}
+func NewWorkflowSchemeService(client service.Client, version string, issueType *WorkflowSchemeIssueTypeService) *WorkflowSchemeService {
 
 	return &WorkflowSchemeService{
 		internalClient: &internalWorkflowSchemeImpl{c: client, version: version},
-	}, nil
+		IssueType:      issueType,
+	}
 }
 
 type WorkflowSchemeService struct {
 	internalClient jira.WorkflowSchemeConnector
+	IssueType      *WorkflowSchemeIssueTypeService
 }
 
 // Gets returns a paginated list of all workflow schemes, not including draft workflow schemes.
diff --git a/jira/internal/workflow_scheme_issue_type_impl.go b/jira/internal/workflow_scheme_issue_type_impl.go
new file mode 100644
index 0000000..5f76754
--- /dev/null
+++ b/jira/internal/workflow_scheme_issue_type_impl.go
@@ -0,0 +1,216 @@
+package internal
+
+import (
+	"context"
+	"fmt"
+	model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
+	"github.com/ctreminiom/go-atlassian/service"
+	"github.com/ctreminiom/go-atlassian/service/jira"
+	"net/http"
+	"net/url"
+	"strings"
+)
+
+func NewWorkflowSchemeIssueTypeService(client service.Client, version string) *WorkflowSchemeIssueTypeService {
+
+	return &WorkflowSchemeIssueTypeService{
+		internalClient: &internalWorkflowSchemeIssueTypeImpl{c: client, version: version},
+	}
+}
+
+type WorkflowSchemeIssueTypeService struct {
+	internalClient jira.WorkflowSchemeIssueTypeConnector
+}
+
+// Get returns the issue type-workflow mapping for an issue type in a workflow scheme.
+//
+// GET /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+//
+// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#get-workflow-for-issue-type-in-workflow-scheme
+func (w *WorkflowSchemeIssueTypeService) Get(ctx context.Context, schemeID int, issueTypeID string, returnDraft bool) (*model.IssueTypeWorkflowMappingScheme, *model.ResponseScheme, error) {
+	return w.internalClient.Get(ctx, schemeID, issueTypeID, returnDraft)
+}
+
+// Set sets the workflow for an issue type in a workflow scheme.
+//
+// Note that active workflow schemes cannot be edited.
+//
+// # If the workflow scheme is active, set updateDraftIfNeeded to true in the request body and a draft workflow scheme
+//
+// is created or updated with the new issue type-workflow mapping.
+//
+// The draft workflow scheme can be published in Jira.
+//
+// PUT /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+//
+// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#set-workflow-for-issue-type-in-workflow-scheme
+func (w *WorkflowSchemeIssueTypeService) Set(ctx context.Context, schemeID int, issueTypeID string, payload *model.IssueTypeWorkflowPayloadScheme) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error) {
+	return w.internalClient.Set(ctx, schemeID, issueTypeID, payload)
+}
+
+// Delete deletes the issue type-workflow mapping for an issue type in a workflow scheme.
+//
+// Note that active workflow schemes cannot be edited.
+//
+// # If the workflow scheme is active, set updateDraftIfNeeded to true and a draft workflow scheme is created or
+//
+// updated with the issue type-workflow mapping deleted.
+//
+// The draft workflow scheme can be published in Jira.
+//
+// DELETE /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+//
+// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#delete-workflow-for-issue-type-in-workflow-scheme
+func (w *WorkflowSchemeIssueTypeService) Delete(ctx context.Context, schemeID int, issueTypeID string, updateDraft bool) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error) {
+	return w.internalClient.Delete(ctx, schemeID, issueTypeID, updateDraft)
+}
+
+// Mapping returns the workflow-issue type mappings for a workflow scheme.
+//
+// GET /rest/api/{2-3}/workflowscheme/{id}/workflow
+//
+// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#get-issue-types-for-workflows-in-workflow-scheme
+func (w *WorkflowSchemeIssueTypeService) Mapping(ctx context.Context, schemeID int, workflowName string, returnDraft bool) ([]*model.IssueTypesWorkflowMappingScheme, *model.ResponseScheme, error) {
+	return w.internalClient.Mapping(ctx, schemeID, workflowName, returnDraft)
+}
+
+type internalWorkflowSchemeIssueTypeImpl struct {
+	c       service.Client
+	version string
+}
+
+func (i *internalWorkflowSchemeIssueTypeImpl) Get(ctx context.Context, schemeID int, issueTypeID string, returnDraft bool) (*model.IssueTypeWorkflowMappingScheme, *model.ResponseScheme, error) {
+
+	if schemeID == 0 {
+		return nil, nil, model.ErrNoWorkflowSchemeIDError
+	}
+
+	if issueTypeID == "" {
+		return nil, nil, model.ErrNoIssueTypeIDError
+	}
+
+	var endpoint strings.Builder
+	endpoint.WriteString(fmt.Sprintf("rest/api/%v/workflowscheme/%v/issuetype/%v", i.version, schemeID, issueTypeID))
+
+	if returnDraft {
+		params := url.Values{}
+		params.Add("returnDraftIfExists", "true")
+
+		endpoint.WriteString(fmt.Sprintf("?%v", params.Encode()))
+	}
+
+	request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint.String(), nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	mapping := new(model.IssueTypeWorkflowMappingScheme)
+	response, err := i.c.Call(request, mapping)
+	if err != nil {
+		return nil, response, err
+	}
+
+	return mapping, response, nil
+}
+
+func (i *internalWorkflowSchemeIssueTypeImpl) Set(ctx context.Context, schemeID int, issueTypeID string, payload *model.IssueTypeWorkflowPayloadScheme) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error) {
+
+	if schemeID == 0 {
+		return nil, nil, model.ErrNoWorkflowSchemeIDError
+	}
+
+	if issueTypeID == "" {
+		return nil, nil, model.ErrNoIssueTypeIDError
+	}
+
+	reader, err := i.c.TransformStructToReader(payload)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	endpoint := fmt.Sprintf("rest/api/%v/workflowscheme/%v/issuetype/%v", i.version, schemeID, issueTypeID)
+
+	request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, reader)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	scheme := new(model.WorkflowSchemeScheme)
+	response, err := i.c.Call(request, scheme)
+	if err != nil {
+		return nil, response, err
+	}
+
+	return scheme, response, nil
+}
+
+func (i *internalWorkflowSchemeIssueTypeImpl) Delete(ctx context.Context, schemeID int, issueTypeID string, updateDraft bool) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error) {
+
+	if schemeID == 0 {
+		return nil, nil, model.ErrNoWorkflowSchemeIDError
+	}
+
+	if issueTypeID == "" {
+		return nil, nil, model.ErrNoIssueTypeIDError
+	}
+
+	var endpoint strings.Builder
+	endpoint.WriteString(fmt.Sprintf("rest/api/%v/workflowscheme/%v/issuetype/%v", i.version, schemeID, issueTypeID))
+
+	if updateDraft {
+		params := url.Values{}
+		params.Add("updateDraftIfNeeded", "true")
+
+		endpoint.WriteString(fmt.Sprintf("?%v", params.Encode()))
+	}
+
+	request, err := i.c.NewRequest(ctx, http.MethodDelete, endpoint.String(), nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	scheme := new(model.WorkflowSchemeScheme)
+	response, err := i.c.Call(request, scheme)
+	if err != nil {
+		return nil, response, err
+	}
+
+	return scheme, response, nil
+}
+
+func (i *internalWorkflowSchemeIssueTypeImpl) Mapping(ctx context.Context, schemeID int, workflowName string, returnDraft bool) ([]*model.IssueTypesWorkflowMappingScheme, *model.ResponseScheme, error) {
+
+	if schemeID == 0 {
+		return nil, nil, model.ErrNoWorkflowSchemeIDError
+	}
+
+	var endpoint strings.Builder
+	endpoint.WriteString(fmt.Sprintf("rest/api/%v/workflowscheme/%v/workflow", i.version, schemeID))
+
+	params := url.Values{}
+
+	if workflowName != "" {
+		params.Add("workflowName", workflowName)
+	}
+
+	if returnDraft {
+		params.Add("returnDraftIfExists", "true")
+	}
+
+	if params.Encode() != "" {
+		endpoint.WriteString(fmt.Sprintf("?%v", params.Encode()))
+	}
+
+	request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint.String(), nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var mapping []*model.IssueTypesWorkflowMappingScheme
+	response, err := i.c.Call(request, &mapping)
+	if err != nil {
+		return nil, response, err
+	}
+
+	return mapping, response, nil
+}
diff --git a/jira/v2/api_client_impl.go b/jira/v2/api_client_impl.go
index 4e9f0f2..99c296a 100644
--- a/jira/v2/api_client_impl.go
+++ b/jira/v2/api_client_impl.go
@@ -332,10 +332,10 @@ func New(httpClient common.HttpClient, site string) (*Client, error) {
 		return nil, err
 	}
 
-	workflowScheme, err := internal.NewWorkflowSchemeService(client, "2")
-	if err != nil {
-		return nil, err
-	}
+	workflowScheme := internal.NewWorkflowSchemeService(
+		client,
+		"2",
+		internal.NewWorkflowSchemeIssueTypeService(client, "2"))
 
 	workflowStatus, err := internal.NewWorkflowStatusService(client, "2")
 	if err != nil {
diff --git a/jira/v3/api_client_impl.go b/jira/v3/api_client_impl.go
index e2acf35..33e14c7 100644
--- a/jira/v3/api_client_impl.go
+++ b/jira/v3/api_client_impl.go
@@ -332,10 +332,10 @@ func New(httpClient common.HttpClient, site string) (*Client, error) {
 		return nil, err
 	}
 
-	workflowScheme, err := internal.NewWorkflowSchemeService(client, "3")
-	if err != nil {
-		return nil, err
-	}
+	workflowScheme := internal.NewWorkflowSchemeService(
+		client,
+		"3",
+		internal.NewWorkflowSchemeIssueTypeService(client, "3"))
 
 	workflowStatus, err := internal.NewWorkflowStatusService(client, "3")
 	if err != nil {
diff --git a/pkg/infra/models/jira_workflow_scheme_issue_type.go b/pkg/infra/models/jira_workflow_scheme_issue_type.go
new file mode 100644
index 0000000..4bfe1fe
--- /dev/null
+++ b/pkg/infra/models/jira_workflow_scheme_issue_type.go
@@ -0,0 +1,18 @@
+package models
+
+type IssueTypeWorkflowMappingScheme struct {
+	IssueType string `json:"issueType,omitempty"`
+	Workflow  string `json:"workflow,omitempty"`
+}
+
+type IssueTypeWorkflowPayloadScheme struct {
+	IssueType           string `json:"issueType,omitempty"`
+	UpdateDraftIfNeeded bool   `json:"updateDraftIfNeeded,omitempty"`
+	Workflow            string `json:"workflow,omitempty"`
+}
+
+type IssueTypesWorkflowMappingScheme struct {
+	Workflow       string   `json:"workflow,omitempty"`
+	IssueTypes     []string `json:"issueTypes,omitempty"`
+	DefaultMapping bool     `json:"defaultMapping,omitempty"`
+}
diff --git a/service/jira/workflow.go b/service/jira/workflow.go
index 139f5ef..b32584e 100644
--- a/service/jira/workflow.go
+++ b/service/jira/workflow.go
@@ -114,6 +114,56 @@ type WorkflowSchemeConnector interface {
 	Assign(ctx context.Context, schemeId, projectId string) (*model.ResponseScheme, error)
 }
 
+// WorkflowSchemeIssueTypeConnector represents the workflows scheme issue type endpoints.
+//
+// Use it to search, get, create, delete, and change workflow issue types.
+type WorkflowSchemeIssueTypeConnector interface {
+
+	// Get returns the issue type-workflow mapping for an issue type in a workflow scheme.
+	//
+	// GET /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+	//
+	// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#get-workflow-for-issue-type-in-workflow-scheme
+	Get(ctx context.Context, schemeID int, issueTypeID string, returnDraft bool) (*model.IssueTypeWorkflowMappingScheme, *model.ResponseScheme, error)
+
+	// Set sets the workflow for an issue type in a workflow scheme.
+	//
+	// Note that active workflow schemes cannot be edited.
+	//
+	// If the workflow scheme is active, set updateDraftIfNeeded to true in the request body and a draft workflow scheme
+	//
+	// is created or updated with the new issue type-workflow mapping.
+	//
+	// The draft workflow scheme can be published in Jira.
+	//
+	// PUT /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+	//
+	// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#set-workflow-for-issue-type-in-workflow-scheme
+	Set(ctx context.Context, schemeID int, issueTypeID string, payload *model.IssueTypeWorkflowPayloadScheme) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error)
+
+	// Delete deletes the issue type-workflow mapping for an issue type in a workflow scheme.
+	//
+	// Note that active workflow schemes cannot be edited.
+	//
+	// If the workflow scheme is active, set updateDraftIfNeeded to true and a draft workflow scheme is created or
+	//
+	// updated with the issue type-workflow mapping deleted.
+	//
+	// The draft workflow scheme can be published in Jira.
+	//
+	// DELETE /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
+	//
+	// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#delete-workflow-for-issue-type-in-workflow-scheme
+	Delete(ctx context.Context, schemeID int, issueTypeID string, updateDraft bool) (*model.WorkflowSchemeScheme, *model.ResponseScheme, error)
+
+	// Mapping returns the workflow-issue type mappings for a workflow scheme.
+	//
+	// GET /rest/api/{2-3}/workflowscheme/{id}/workflow
+	//
+	// https://docs.go-atlassian.io/jira-software-cloud/workflow/scheme/issue-type#get-issue-types-for-workflows-in-workflow-scheme
+	Mapping(ctx context.Context, schemeID int, workflowName string, returnDraft bool) ([]*model.IssueTypesWorkflowMappingScheme, *model.ResponseScheme, error)
+}
+
 // WorkflowStatusConnector represents the workflows statuses.
 //
 // Use it to search, get, create, delete, and change statuses.


Test patch:
diff --git a/jira/internal/workflow_scheme_impl_test.go b/jira/internal/workflow_scheme_impl_test.go
index 31ff2bf..f09463f 100644
--- a/jira/internal/workflow_scheme_impl_test.go
+++ b/jira/internal/workflow_scheme_impl_test.go
@@ -125,8 +125,7 @@ func Test_internalWorkflowSchemeImpl_Gets(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResult, gotResponse, err := newService.Gets(testCase.args.ctx, testCase.args.startAt, testCase.args.maxResults)
 
@@ -273,8 +272,7 @@ func Test_internalWorkflowSchemeImpl_Get(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResult, gotResponse, err := newService.Get(testCase.args.ctx, testCase.args.schemeId, testCase.args.returnDraftIfExists)
 
@@ -417,8 +415,7 @@ func Test_internalWorkflowSchemeImpl_Delete(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResponse, err := newService.Delete(testCase.args.ctx, testCase.args.schemeId)
 
@@ -560,8 +557,7 @@ func Test_internalWorkflowSchemeImpl_Associations(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResult, gotResponse, err := newService.Associations(testCase.args.ctx, testCase.args.projectIds)
 
@@ -735,8 +731,7 @@ func Test_internalWorkflowSchemeImpl_Assign(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResponse, err := newService.Assign(testCase.args.ctx, testCase.args.schemeId, testCase.args.projectId)
 
@@ -903,8 +898,7 @@ func Test_internalWorkflowSchemeImpl_Update(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResult, gotResponse, err := newService.Update(testCase.args.ctx, testCase.args.schemeId, testCase.args.payload)
 
@@ -1059,8 +1053,7 @@ func Test_internalWorkflowSchemeImpl_Create(t *testing.T) {
 				testCase.on(&testCase.fields)
 			}
 
-			newService, err := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version)
-			assert.NoError(t, err)
+			newService := NewWorkflowSchemeService(testCase.fields.c, testCase.fields.version, nil)
 
 			gotResult, gotResponse, err := newService.Create(testCase.args.ctx, testCase.args.payload)
 
@@ -1117,21 +1110,8 @@ func Test_NewWorkflowSchemeService(t *testing.T) {
 	}
 	for _, testCase := range testCases {
 		t.Run(testCase.name, func(t *testing.T) {
-			got, err := NewWorkflowSchemeService(testCase.args.client, testCase.args.version)
-
-			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, got, nil)
-			}
+			got := NewWorkflowSchemeService(testCase.args.client, testCase.args.version, nil)
+			assert.NotEqual(t, got, nil)
 		})
 	}
 }
diff --git a/jira/internal/workflow_scheme_issue_type_impl_test.go b/jira/internal/workflow_scheme_issue_type_impl_test.go
new file mode 100644
index 0000000..b337271
--- /dev/null
+++ b/jira/internal/workflow_scheme_issue_type_impl_test.go
@@ -0,0 +1,673 @@
+package internal
+
+import (
+	"bytes"
+	"context"
+	"errors"
+	model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
+	"github.com/ctreminiom/go-atlassian/service"
+	"github.com/ctreminiom/go-atlassian/service/mocks"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
+	"net/http"
+	"testing"
+)
+
+func Test_internalWorkflowSchemeIssueTypeImpl_Get(t *testing.T) {
+
+	type fields struct {
+		c       service.Client
+		version string
+	}
+
+	type args struct {
+		ctx         context.Context
+		schemeID    int
+		issueTypeID string
+		returnDraft bool
+	}
+
+	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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				returnDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/3/workflowscheme/10002/issuetype/4?returnDraftIfExists=true",
+					nil).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.IssueTypeWorkflowMappingScheme{}).
+					Return(&model.ResponseScheme{}, nil)
+
+				fields.c = client
+			},
+			wantErr: false,
+			Err:     nil,
+		},
+
+		{
+			name:   "when the workflow scheme id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx: context.TODO(),
+			},
+			wantErr: true,
+			Err:     model.ErrNoWorkflowSchemeIDError,
+		},
+
+		{
+			name:   "when the issue type id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx:      context.TODO(),
+				schemeID: 10002,
+			},
+			wantErr: true,
+			Err:     model.ErrNoIssueTypeIDError,
+		},
+
+		{
+			name:   "when the api version is v2",
+			fields: fields{version: "2"},
+			args: args{
+				ctx:         context.TODO(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				returnDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/2/workflowscheme/10002/issuetype/4?returnDraftIfExists=true",
+					nil).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.IssueTypeWorkflowMappingScheme{}).
+					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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				returnDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/3/workflowscheme/10002/issuetype/4?returnDraftIfExists=true",
+					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 := NewWorkflowSchemeIssueTypeService(testCase.fields.c, testCase.fields.version)
+
+			gotResult, gotResponse, err := newService.Get(testCase.args.ctx, testCase.args.schemeID, testCase.args.issueTypeID,
+				testCase.args.returnDraft)
+
+			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)
+			}
+
+		})
+	}
+}
+
+func Test_internalWorkflowSchemeIssueTypeImpl_Mapping(t *testing.T) {
+
+	type fields struct {
+		c       service.Client
+		version string
+	}
+
+	type args struct {
+		ctx          context.Context
+		schemeID     int
+		workflowName string
+		returnDraft  bool
+	}
+
+	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(),
+				schemeID:     10002,
+				workflowName: "jira workflow ",
+				returnDraft:  true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/3/workflowscheme/10002/workflow?returnDraftIfExists=true&workflowName=jira+workflow+",
+					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 workflow scheme id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx: context.TODO(),
+			},
+			wantErr: true,
+			Err:     model.ErrNoWorkflowSchemeIDError,
+		},
+
+		{
+			name:   "when the api version is v2",
+			fields: fields{version: "2"},
+			args: args{
+				ctx:          context.TODO(),
+				schemeID:     10002,
+				workflowName: "jira workflow ",
+				returnDraft:  true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/2/workflowscheme/10002/workflow?returnDraftIfExists=true&workflowName=jira+workflow+",
+					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(),
+				schemeID:     10002,
+				workflowName: "jira workflow ",
+				returnDraft:  true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodGet,
+					"rest/api/3/workflowscheme/10002/workflow?returnDraftIfExists=true&workflowName=jira+workflow+",
+					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 := NewWorkflowSchemeIssueTypeService(testCase.fields.c, testCase.fields.version)
+
+			gotResult, gotResponse, err := newService.Mapping(testCase.args.ctx, testCase.args.schemeID, testCase.args.workflowName,
+				testCase.args.returnDraft)
+
+			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)
+			}
+
+		})
+	}
+}
+
+func Test_internalWorkflowSchemeIssueTypeImpl_Delete(t *testing.T) {
+
+	type fields struct {
+		c       service.Client
+		version string
+	}
+
+	type args struct {
+		ctx         context.Context
+		schemeID    int
+		issueTypeID string
+		updateDraft bool
+	}
+
+	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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				updateDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodDelete,
+					"rest/api/3/workflowscheme/10002/issuetype/4?updateDraftIfNeeded=true",
+					nil).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.WorkflowSchemeScheme{}).
+					Return(&model.ResponseScheme{}, nil)
+
+				fields.c = client
+			},
+			wantErr: false,
+			Err:     nil,
+		},
+
+		{
+			name:   "when the workflow scheme id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx: context.TODO(),
+			},
+			wantErr: true,
+			Err:     model.ErrNoWorkflowSchemeIDError,
+		},
+
+		{
+			name:   "when the issue type id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx:      context.TODO(),
+				schemeID: 10002,
+			},
+			wantErr: true,
+			Err:     model.ErrNoIssueTypeIDError,
+		},
+
+		{
+			name:   "when the api version is v2",
+			fields: fields{version: "2"},
+			args: args{
+				ctx:         context.TODO(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				updateDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodDelete,
+					"rest/api/2/workflowscheme/10002/issuetype/4?updateDraftIfNeeded=true",
+					nil).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.WorkflowSchemeScheme{}).
+					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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				updateDraft: true,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodDelete,
+					"rest/api/3/workflowscheme/10002/issuetype/4?updateDraftIfNeeded=true",
+					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 := NewWorkflowSchemeIssueTypeService(testCase.fields.c, testCase.fields.version)
+
+			gotResult, gotResponse, err := newService.Delete(testCase.args.ctx, testCase.args.schemeID, testCase.args.issueTypeID,
+				testCase.args.updateDraft)
+
+			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)
+			}
+
+		})
+	}
+}
+
+func Test_internalWorkflowSchemeIssueTypeImpl_Set(t *testing.T) {
+
+	payloadMocked := &model.IssueTypeWorkflowPayloadScheme{
+		IssueType:           "193",
+		UpdateDraftIfNeeded: true,
+		Workflow:            "jira workflow sample",
+	}
+
+	type fields struct {
+		c       service.Client
+		version string
+	}
+
+	type args struct {
+		ctx         context.Context
+		schemeID    int
+		issueTypeID string
+		payload     *model.IssueTypeWorkflowPayloadScheme
+	}
+
+	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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				payload:     payloadMocked,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("TransformStructToReader",
+					payloadMocked).
+					Return(bytes.NewReader([]byte{}), nil)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodPut,
+					"rest/api/3/workflowscheme/10002/issuetype/4",
+					bytes.NewReader([]byte{})).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.WorkflowSchemeScheme{}).
+					Return(&model.ResponseScheme{}, nil)
+
+				fields.c = client
+			},
+			wantErr: false,
+			Err:     nil,
+		},
+
+		{
+			name:   "when the workflow scheme id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx: context.TODO(),
+			},
+			wantErr: true,
+			Err:     model.ErrNoWorkflowSchemeIDError,
+		},
+
+		{
+			name:   "when the issue type id is not provided",
+			fields: fields{version: "3"},
+			args: args{
+				ctx:      context.TODO(),
+				schemeID: 10002,
+			},
+			wantErr: true,
+			Err:     model.ErrNoIssueTypeIDError,
+		},
+
+		{
+			name:   "when the api version is v2",
+			fields: fields{version: "2"},
+			args: args{
+				ctx:         context.TODO(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				payload:     payloadMocked,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("TransformStructToReader",
+					payloadMocked).
+					Return(bytes.NewReader([]byte{}), nil)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodPut,
+					"rest/api/2/workflowscheme/10002/issuetype/4",
+					bytes.NewReader([]byte{})).
+					Return(&http.Request{}, nil)
+
+				client.On("Call",
+					&http.Request{},
+					&model.WorkflowSchemeScheme{}).
+					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(),
+				schemeID:    10002,
+				issueTypeID: "4",
+				payload:     payloadMocked,
+			},
+			on: func(fields *fields) {
+
+				client := mocks.NewClient(t)
+
+				client.On("TransformStructToReader",
+					payloadMocked).
+					Return(bytes.NewReader([]byte{}), nil)
+
+				client.On("NewRequest",
+					context.Background(),
+					http.MethodPut,
+					"rest/api/3/workflowscheme/10002/issuetype/4",
+					bytes.NewReader([]byte{})).
+					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 := NewWorkflowSchemeIssueTypeService(testCase.fields.c, testCase.fields.version)
+
+			gotResult, gotResponse, err := newService.Set(testCase.args.ctx, testCase.args.schemeID, testCase.args.issueTypeID,
+				testCase.args.payload)
+
+			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)
+			}
+
+		})
+	}
+}