Skip to content

Commit

Permalink
fixed the test cases on the jira_issue_custom_fields.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreminiom committed Sep 23, 2023
1 parent 63aca31 commit e0af678
Show file tree
Hide file tree
Showing 4 changed files with 1,196 additions and 105 deletions.
1 change: 1 addition & 0 deletions pkg/infra/models/agile_sprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ type SprintDetailScheme struct {
CompleteDate string `json:"completeDate,omitempty"`
OriginBoardID int `json:"originBoardId,omitempty"`
Goal string `json:"goal,omitempty"`
BoardID int `json:"boardId,omitempty"`
}
6 changes: 5 additions & 1 deletion pkg/infra/models/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,20 @@ var (
ErrNoSiteError = errors.New("client: no atlassian site set")
ErrNilPayloadError = errors.New("client: please provide the necessary payload struct")
ErrNonPayloadPointerError = errors.New("client: please provide a valid payload struct pointer (&)")
ErrNoFieldInformationError = errors.New("custom-field: please provide a buffer with a valid fields object")
ErrNoFieldInformationError = errors.New("custom-field: no json fields object found")
ErrNoFloatTypeError = errors.New("custom-field: no float type set")
ErrNoCustomFieldUnmarshalError = errors.New("custom-field: no valid json provided")
ErrNoMultiSelectTypeError = errors.New("custom-field: no multiselect type found")
ErrNoSprintTypeError = errors.New("custom-field: no sprint type found")
ErrNoMultiVersionTypeError = errors.New("custom-field: no multiversion type found")
ErrNoUrlTypeError = errors.New("custom-field: no url type set")
ErrNoTextTypeError = errors.New("custom-field: no text type set")
ErrNoDateTimeTypeError = errors.New("custom-field: no date-time type set")
ErrNoDateTypeError = errors.New("custom-field: no date type set")
ErrNoSelectTypeError = errors.New("custom-field: no select type set")
ErrNoButtonTypeError = errors.New("custom-field: no button type set")
ErrNoUserTypeError = errors.New("custom-field: no user type set")
ErrNoLabelsTypeError = errors.New("custom-field: no labels type set")
ErrNoMultiUserTypeError = errors.New("custom-field: no multi-user type set")
ErrNoCheckBoxTypeError = errors.New("custom-field: no check-box type set")
ErrNoCascadingParentError = errors.New("custom-field: no cascading parent value set")
Expand Down
61 changes: 28 additions & 33 deletions pkg/infra/models/jira_issue_custom_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ func ParseCascadingSelectCustomField(buffer bytes.Buffer, customField string) (*
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoCascadingParentError
}

var cascading CascadingSelectScheme
if err := json.Unmarshal([]byte(raw.Get(path).String()), &cascading); err != nil {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoCascadingParentError
}

return &cascading, nil
Expand Down Expand Up @@ -572,7 +572,7 @@ func ParseMultiVersionCustomField(buffer bytes.Buffer, customField string) ([]*V
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoMultiVersionTypeError
}

var versions []*VersionDetailScheme
Expand Down Expand Up @@ -701,7 +701,7 @@ func ParseUserPickerCustomField(buffer bytes.Buffer, customField string) (*UserD
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoUserTypeError
}

var user UserDetailScheme
Expand Down Expand Up @@ -824,15 +824,10 @@ func ParseStringCustomField(buffer bytes.Buffer, customField string) (string, er
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return "", ErrNoMultiSelectTypeError
}

var textField string
if err := json.Unmarshal([]byte(raw.Get(path).String()), &textField); err != nil {
return "", ErrNoMultiSelectTypeError
return "", ErrNoTextTypeError
}

return textField, nil
return raw.Get(path).String(), nil
}

// ParseStringCustomFields extracts and parses the textfield customfield information from multiple issues using a bytes.Buffer.
Expand Down Expand Up @@ -913,26 +908,26 @@ func ParseStringCustomFields(buffer bytes.Buffer, customField string) (map[strin
return customfieldsAsMap, nil

Check warning on line 908 in pkg/infra/models/jira_issue_custom_fields.go

View check run for this annotation

Codecov / codecov/patch

pkg/infra/models/jira_issue_custom_fields.go#L908

Added line #L908 was not covered by tests
}

// ParseStringCustomField parses a textfield custom field from the given buffer data
// ParseFloatCustomField parses a float custom field from the given buffer data
// associated with the specified custom field ID and returns string
//
// Parameters:
// - customfieldID: A string representing the unique identifier of the custom field.
// - buffer: A bytes.Buffer containing the serialized data to be parsed.
//
// Returns:
// - string: the customfield value as string type
// - float64: the customfield value as float64 type
//
// Example usage:
//
// customfieldID := "customfield_10001"
// buffer := bytes.NewBuffer([]byte{ /* Serialized data */ })
// textField, err := ParseStringCustomField(customfieldID, buffer)
// floatField, err := ParseFloatCustomField(customfieldID, buffer)
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Println(textField)
// fmt.Println(floatField)
func ParseFloatCustomField(buffer bytes.Buffer, customField string) (float64, error) {

raw := gjson.ParseBytes(buffer.Bytes())
Expand All @@ -946,12 +941,12 @@ func ParseFloatCustomField(buffer bytes.Buffer, customField string) (float64, er
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return 0, ErrNoMultiSelectTypeError
return 0, ErrNoFloatTypeError
}

var textFloat float64
if err := json.Unmarshal([]byte(raw.Get(path).String()), &textFloat); err != nil {
return 0, ErrNoMultiSelectTypeError
return 0, ErrNoFloatTypeError
}

return textFloat, nil
Expand Down Expand Up @@ -1035,26 +1030,26 @@ func ParseFloatCustomFields(buffer bytes.Buffer, customField string) (map[string
return customfieldsAsMap, nil

Check warning on line 1030 in pkg/infra/models/jira_issue_custom_fields.go

View check run for this annotation

Codecov / codecov/patch

pkg/infra/models/jira_issue_custom_fields.go#L1030

Added line #L1030 was not covered by tests
}

// ParseLabelCustomField parses a textfield custom field from the given buffer data
// associated with the specified custom field ID and returns string
// ParseLabelCustomField parses a textfield slice custom field from the given buffer data
// associated with the specified custom field ID and returns string slice
//
// Parameters:
// - customfieldID: A string representing the unique identifier of the custom field.
// - buffer: A bytes.Buffer containing the serialized data to be parsed.
//
// Returns:
// - string: the customfield value as string type
// - []string: the customfield value as string slice type
//
// Example usage:
//
// customfieldID := "customfield_10001"
// buffer := bytes.NewBuffer([]byte{ /* Serialized data */ })
// textField, err := ParseStringCustomField(customfieldID, buffer)
// labels, err := ParseLabelCustomField(customfieldID, buffer)
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Println(textField)
// fmt.Println(labels)
func ParseLabelCustomField(buffer bytes.Buffer, customField string) ([]string, error) {

raw := gjson.ParseBytes(buffer.Bytes())
Expand All @@ -1068,12 +1063,12 @@ func ParseLabelCustomField(buffer bytes.Buffer, customField string) ([]string, e
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoLabelsTypeError
}

var labels []string
if err := json.Unmarshal([]byte(raw.Get(path).String()), &labels); err != nil {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoLabelsTypeError
}

return labels, nil
Expand Down Expand Up @@ -1190,12 +1185,12 @@ func ParseSprintCustomField(buffer bytes.Buffer, customField string) ([]*SprintD
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoSprintTypeError
}

var sprints []*SprintDetailScheme
if err := json.Unmarshal([]byte(raw.Get(path).String()), &sprints); err != nil {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoSprintTypeError
}

return sprints, nil
Expand Down Expand Up @@ -1280,26 +1275,26 @@ func ParseSprintCustomFields(buffer bytes.Buffer, customField string) (map[strin
return customfieldsAsMap, nil

Check warning on line 1275 in pkg/infra/models/jira_issue_custom_fields.go

View check run for this annotation

Codecov / codecov/patch

pkg/infra/models/jira_issue_custom_fields.go#L1275

Added line #L1275 was not covered by tests
}

// ParseSelectCustomField parses a sprints custom field from the given buffer data
// associated with the specified custom field ID and returns string
// ParseSelectCustomField parses a select custom field from the given buffer data
// associated with the specified custom field ID and returns struct
//
// Parameters:
// - customfieldID: A string representing the unique identifier of the custom field.
// - buffer: A bytes.Buffer containing the serialized data to be parsed.
//
// Returns:
// - string: the customfield value as string type
// - CustomFieldContextOptionScheme: the customfield value as CustomFieldContextOptionScheme type
//
// Example usage:
//
// customfieldID := "customfield_10001"
// buffer := bytes.NewBuffer([]byte{ /* Serialized data */ })
// textField, err := ParseStringCustomField(customfieldID, buffer)
// option, err := ParseSelectCustomField(customfieldID, buffer)
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Println(textField)
// fmt.Println(option.ID, option.Value)
func ParseSelectCustomField(buffer bytes.Buffer, customField string) (*CustomFieldContextOptionScheme, error) {

raw := gjson.ParseBytes(buffer.Bytes())
Expand All @@ -1313,12 +1308,12 @@ func ParseSelectCustomField(buffer bytes.Buffer, customField string) (*CustomFie
// Check if the issue iteration contains information on the customfield selected,
// if not, continue
if raw.Get(path).Type == gjson.Null {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoSelectTypeError
}

var sprints *CustomFieldContextOptionScheme
if err := json.Unmarshal([]byte(raw.Get(path).String()), &sprints); err != nil {
return nil, ErrNoMultiSelectTypeError
return nil, ErrNoSelectTypeError
}

return sprints, nil
Expand Down
Loading

0 comments on commit e0af678

Please sign in to comment.