Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/infra/models/jira_custom_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ func (c *CustomFields) Text(customFieldID, textValue string) error {
return nil
}

func (c *CustomFields) TextArea(customFieldID string, textAreaValue *CommentNodeScheme) error {

Check warning

Code scanning / Revive (reported by Codacy)

exported method CustomFields.TextArea should have comment or be unexported

exported method CustomFields.TextArea should have comment or be unexported

if len(customFieldID) == 0 {
return ErrNoFieldIDError
}

if textAreaValue == nil {
return ErrNoTextTypeError
}

var fieldNode = map[string]interface{}{}
fieldNode[customFieldID] = textAreaValue

var fieldsNode = map[string]interface{}{}
fieldsNode["fields"] = fieldNode

c.Fields = append(c.Fields, fieldsNode)
return nil
}

// DateTime adds a datetime custom field to the collection.
func (c *CustomFields) DateTime(customFieldID string, dateValue time.Time) error {

Expand Down
86 changes: 85 additions & 1 deletion pkg/infra/models/jira_custom_fields_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package models

import (
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestCustomFields_Cascading(t *testing.T) {
Expand Down Expand Up @@ -967,3 +968,86 @@ func TestCustomFields_Users(t *testing.T) {
})
}
}

func TestCustomFields_TextArea(t *testing.T) {
type fields struct {
Fields []map[string]interface{}
}
type args struct {
customFieldID string
textAreaValue *CommentNodeScheme
}
testCases := []struct {
name string
fields fields
args args
wantErr bool
Err error
}{
{
name: "when the parameters are correct",
fields: fields{},
args: args{
customFieldID: "customfield_1000",
textAreaValue: &CommentNodeScheme{
Type: "doc",
Version: 1,
Content: []*CommentNodeScheme{
{
Type: "paragraph",
Content: []*CommentNodeScheme{
{
Type: "text",
Text: "Example comment",
},
},
},
},
},
},
wantErr: false,
Err: nil,
},

{
name: "when the custom-field is not provided",
fields: fields{},
args: args{
customFieldID: "",
textAreaValue: &CommentNodeScheme{Type: "doc", Version: 1, Content: []*CommentNodeScheme{{Type: "paragraph", Content: []*CommentNodeScheme{{Type: "text", Text: "Example comment"}}}}},
},
wantErr: true,
Err: ErrNoFieldIDError,
},

{
name: "when the text area value is not provided",
fields: fields{},
args: args{
customFieldID: "customfield_1000",
textAreaValue: nil,
},
wantErr: true,
Err: ErrNoTextTypeError,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
c := &CustomFields{
Fields: testCase.fields.Fields,
}

err := c.TextArea(testCase.args.customFieldID, testCase.args.textAreaValue)
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)
}
})
}
}