mirror of
https://github.com/go-gitea/gitea.git
synced 2025-01-02 01:17:43 +03:00
Add test and fix problem for API routers
This commit is contained in:
parent
0ab222faaa
commit
bd74d3555c
@ -89,6 +89,7 @@ func (m *Milestone) AfterLoad(session *xorm.Session) {
|
||||
if m.DeadlineUnix == 0 {
|
||||
return
|
||||
}
|
||||
// for legacy reasons, all years after 9000 are considered as no deadline
|
||||
if m.DeadlineUnix.Year() > 9000 {
|
||||
m.DeadlineUnix = 0
|
||||
m.IsOverdue = false
|
||||
|
@ -260,7 +260,10 @@ func ToAPIMilestone(m *issues_model.Milestone) *api.Milestone {
|
||||
if m.IsClosed {
|
||||
apiMilestone.Closed = m.ClosedDateUnix.AsTimePtr()
|
||||
}
|
||||
if m.DeadlineUnix.Year() < 9999 {
|
||||
// for legacy reasons, all years after 9000 are considered as no deadline
|
||||
if m.DeadlineUnix.Year() > 9000 || m.DeadlineUnix == 0 {
|
||||
apiMilestone.Deadline = nil
|
||||
} else {
|
||||
apiMilestone.Deadline = m.DeadlineUnix.AsTimePtr()
|
||||
}
|
||||
return apiMilestone
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
@ -59,6 +60,7 @@ func TestAPIIssuesMilestone(t *testing.T) {
|
||||
DecodeJSON(t, resp, &apiMilestone)
|
||||
assert.Equal(t, "wow", apiMilestone.Title)
|
||||
assert.Equal(t, structs.StateClosed, apiMilestone.State)
|
||||
assert.Equal(t, (*time.Time)(nil), apiMilestone.Deadline)
|
||||
|
||||
var apiMilestones []structs.Milestone
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?state=%s", owner.Name, repo.Name, "all")).
|
||||
@ -66,6 +68,7 @@ func TestAPIIssuesMilestone(t *testing.T) {
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiMilestones)
|
||||
assert.Len(t, apiMilestones, 4)
|
||||
assert.Equal(t, (*time.Time)(nil), apiMilestones[0].Deadline)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%s", owner.Name, repo.Name, apiMilestones[2].Title)).
|
||||
AddTokenAuth(token)
|
||||
|
Loading…
Reference in New Issue
Block a user