Skip to content

Commit

Permalink
fix: add test case for customfield TextArea function
Browse files Browse the repository at this point in the history
  • Loading branch information
sancyx committed Aug 23, 2024
1 parent eb27f4d commit 04bbb0d
Showing 1 changed file with 85 additions and 1 deletion.
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)
}
})
}
}

0 comments on commit 04bbb0d

Please sign in to comment.