1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-19 20:57:47 +02:00

Add CreatedTime() (time.Time, error) func to ChangelogHistory

This commit is contained in:
Oleh Roshnivskyi 2018-07-21 23:42:58 +03:00
parent 8201aaa4d4
commit e25bafc579
2 changed files with 42 additions and 0 deletions

View File

@ -1088,3 +1088,13 @@ func (s *IssueService) RemoveWatcher(issueID string, userName string) (*Response
return resp, err
}
func (c ChangelogHistory) CreatedTime() (time.Time, error) {
var t time.Time
// Ignore null
if string(c.Created) == "null" {
return t, nil
}
t, err := time.Parse("2006-01-02T15:04:05.999-0700", c.Created)
return t, err
}

View File

@ -10,6 +10,7 @@ import (
"testing"
"github.com/trivago/tgo/tcontainer"
"time"
)
func TestIssueService_Get_Success(t *testing.T) {
@ -1308,3 +1309,34 @@ func TestIssueService_GetWatchers(t *testing.T) {
t.Error("Expected watcher name fred")
}
}
func TestIssueService_Get_Fields_Changelog(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10002", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/issue/10002")
fmt.Fprint(w, `{"expand":"changelog","id":"10002","self":"http://www.example.com/jira/rest/api/2/issue/10002","key":"EX-1","changelog":{"startAt": 0,"maxResults": 1, "total": 1, "histories": [{"id": "10002", "author": {"self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "key": "fred", "emailAddress": "fred@example.com", "avatarUrls": {"48x48": "http://www.example.com/secure/useravatar?ownerId=fred&avatarId=33072", "24x24": "http://www.example.com/secure/useravatar?size=small&ownerId=fred&avatarId=33072", "16x16": "http://www.example.com/secure/useravatar?size=xsmall&ownerId=fred&avatarId=33072", "32x32": "http://www.example.com/secure/useravatar?size=medium&ownerId=fred&avatarId=33072"},"displayName":"Fred","active": true,"timeZone":"Australia/Sydney"},"created":"2018-06-20T16:50:35.000+0300","items":[{"field":"Rank","fieldtype":"custom","from":"","fromString":"","to":"","toString":"Ranked higher"}]}]}}`)
})
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand:"changelog"})
if issue == nil {
t.Error("Expected issue. Issue is nil")
}
if len(issue.Changelog.Histories) != 1 {
t.Errorf("Expected one history item, %v found", len(issue.Changelog.Histories))
}
if issue.Changelog.Histories[0].Created != "2018-06-20T16:50:35.000+0300" {
t.Errorf("Expected created time of history item 2018-06-20T16:50:35.000+0300, %v got", issue.Changelog.Histories[0].Created)
}
tm, _ := time.Parse("2006-01-02T15:04:05.999-0700", "2018-06-20T16:50:35.000+0300")
if ct, _ := issue.Changelog.Histories[0].CreatedTime(); ct != tm {
t.Errorf("Expected CreatedTime func return 2018-06-20T16:50:35.000+0300 time, %v got", ct)
}
}