Files
forge/tests/integration/api_issue_milestone_test.go
zeekayandHanzo Dev 9a07b4d089 legal: Hanzo AI, Inc. copyright above the upstream notices
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git),
so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form
used by the handful of files that had ours.

Shape is now:

	// Copyright 2026 Hanzo AI, Inc. All rights reserved.
	// Copyright 2015 The Gogs Authors. All rights reserved.
	// Copyright 2019 The Gitea Authors. All rights reserved.
	// SPDX-License-Identifier: MIT

Ours on top, theirs retained verbatim. Retained because MIT requires it, and
separately because they are true — those authors did write that code.

Not renamed to "The Git Authors": Git is a different project under a different
license, and putting its name here would attribute this code to people who have
nothing to do with it. Adding our line is the fix; overwriting theirs would have
been both a licence violation and a false statement.

gofmt still reports import-order drift in some of these files. It predates this
change (verified against a stash) and is left alone rather than burying a
one-line-per-file legal change under 3000 files of unrelated reordering.

Build clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 13:49:52 -07:00

87 lines
3.3 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/http"
"testing"
auth_model "github.com/hanzoai/git/models/auth"
issues_model "github.com/hanzoai/git/models/issues"
repo_model "github.com/hanzoai/git/models/repo"
"github.com/hanzoai/git/models/unittest"
user_model "github.com/hanzoai/git/models/user"
"github.com/hanzoai/git/modules/structs"
"github.com/hanzoai/git/tests"
"github.com/stretchr/testify/assert"
)
func TestAPIIssuesMilestone(t *testing.T) {
defer tests.PrepareTestEnv(t)()
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: milestone.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
assert.Equal(t, int64(1), int64(milestone.NumIssues))
assert.Equal(t, structs.StateOpen, milestone.State())
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
// update values of issue
milestoneState := "closed"
urlStr := fmt.Sprintf("/v1/repos/%s/%s/milestones/%d", owner.Name, repo.Name, milestone.ID)
req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{
State: &milestoneState,
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
apiMilestone := DecodeJSON(t, resp, &structs.Milestone{})
assert.EqualValues(t, "closed", apiMilestone.State)
req = NewRequest(t, "GET", urlStr).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
apiMilestone2 := DecodeJSON(t, resp, &structs.Milestone{})
assert.EqualValues(t, "closed", apiMilestone2.State)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/v1/repos/%s/%s/milestones", owner.Name, repo.Name), structs.CreateMilestoneOption{
Title: "wow",
Description: "closed one",
State: "closed",
}).AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusCreated)
apiMilestone = DecodeJSON(t, resp, &structs.Milestone{})
assert.Equal(t, "wow", apiMilestone.Title)
assert.Equal(t, structs.StateClosed, apiMilestone.State)
assert.Nil(t, apiMilestone.Deadline)
req = NewRequest(t, "GET", fmt.Sprintf("/v1/repos/%s/%s/milestones?state=%s", owner.Name, repo.Name, "all")).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
apiMilestones := DecodeJSON(t, resp, []structs.Milestone{})
assert.Len(t, apiMilestones, 4)
assert.Nil(t, apiMilestones[0].Deadline)
req = NewRequest(t, "GET", fmt.Sprintf("/v1/repos/%s/%s/milestones/%s", owner.Name, repo.Name, apiMilestones[2].Title)).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
apiMilestone = DecodeJSON(t, resp, &structs.Milestone{})
assert.Equal(t, apiMilestones[2], *apiMilestone)
req = NewRequest(t, "GET", fmt.Sprintf("/v1/repos/%s/%s/milestones?state=%s&name=%s", owner.Name, repo.Name, "all", "milestone2")).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
apiMilestones = DecodeJSON(t, resp, []structs.Milestone{})
assert.Len(t, apiMilestones, 1)
assert.Equal(t, int64(2), apiMilestones[0].ID)
req = NewRequest(t, "DELETE", fmt.Sprintf("/v1/repos/%s/%s/milestones/%d", owner.Name, repo.Name, apiMilestone.ID)).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
}