Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for textarea custom fields #253

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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 @@
return nil
}

func (c *CustomFields) TextArea(customFieldID string, textAreaValue *CommentNodeScheme) error {
Dismissed Show dismissed Hide dismissed

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)
}
})
}
}
Loading