[FEAT] allow setting the update date on issues and comments (squash) do not use token= query param
See https://codeberg.org/forgejo/forgejo/commit/33439b733a
This commit is contained in:
parent
868b7a436f
commit
c5139a75b9
5 changed files with 44 additions and 44 deletions
|
@ -132,8 +132,8 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
|
|||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets?token=%s",
|
||||
repoOwner.Name, repo.Name, comment.ID, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets",
|
||||
repoOwner.Name, repo.Name, comment.ID)
|
||||
|
||||
filename := "image.png"
|
||||
buff := generateImg()
|
||||
|
@ -151,7 +151,7 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
|
|||
err = writer.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body)
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
|
||||
req.Header.Add("Content-Type", writer.FormDataContentType())
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
apiAttachment := new(api.Attachment)
|
||||
|
@ -171,7 +171,7 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
|
|||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
urlStr += fmt.Sprintf("&updated_at=%s", updatedAt.UTC().Format(time.RFC3339))
|
||||
urlStr += fmt.Sprintf("?updated_at=%s", updatedAt.UTC().Format(time.RFC3339))
|
||||
|
||||
// Setup multi-part
|
||||
writer := multipart.NewWriter(body)
|
||||
|
@ -182,7 +182,7 @@ func TestAPICreateCommentAttachmentAutoDate(t *testing.T) {
|
|||
err = writer.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body)
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
|
||||
req.Header.Add("Content-Type", writer.FormDataContentType())
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
apiAttachment := new(api.Attachment)
|
||||
|
|
|
@ -120,8 +120,8 @@ func TestAPICreateCommentAutoDate(t *testing.T) {
|
|||
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
|
||||
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments?token=%s",
|
||||
repoOwner.Name, repo.Name, issue.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments",
|
||||
repoOwner.Name, repo.Name, issue.Index)
|
||||
const commentBody = "Comment body"
|
||||
|
||||
t.Run("WithAutoDate", func(t *testing.T) {
|
||||
|
@ -129,7 +129,7 @@ func TestAPICreateCommentAutoDate(t *testing.T) {
|
|||
|
||||
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
||||
"body": commentBody,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
@ -151,7 +151,7 @@ func TestAPICreateCommentAutoDate(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{
|
||||
Body: commentBody,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
@ -177,13 +177,13 @@ func TestAPICommentXRefAutoDate(t *testing.T) {
|
|||
|
||||
// Create a comment mentioning issue #2 and check that a xref comment was added
|
||||
// in issue #2
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments?token=%s",
|
||||
repoOwner.Name, repo.Name, issue.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments",
|
||||
repoOwner.Name, repo.Name, issue.Index)
|
||||
|
||||
commentBody := "mention #2"
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{
|
||||
Body: commentBody,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var createdComment api.Comment
|
||||
DecodeJSON(t, resp, &createdComment)
|
||||
|
@ -196,13 +196,13 @@ func TestAPICommentXRefAutoDate(t *testing.T) {
|
|||
assert.LessOrEqual(t, updatedSince, time.Minute)
|
||||
|
||||
// Remove the mention to issue #2 and check that the xref was neutered
|
||||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d?token=%s",
|
||||
repoOwner.Name, repo.Name, createdComment.ID, token)
|
||||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d",
|
||||
repoOwner.Name, repo.Name, createdComment.ID)
|
||||
|
||||
newCommentBody := "no mention"
|
||||
req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{
|
||||
Body: newCommentBody,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
@ -223,15 +223,15 @@ func TestAPICommentXRefAutoDate(t *testing.T) {
|
|||
|
||||
// Create a comment mentioning issue #2 and check that a xref comment was added
|
||||
// in issue #2
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments?token=%s",
|
||||
repoOwner.Name, repo.Name, issue.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments",
|
||||
repoOwner.Name, repo.Name, issue.Index)
|
||||
|
||||
commentBody := "re-mention #2"
|
||||
updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{
|
||||
Body: commentBody,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var createdComment api.Comment
|
||||
DecodeJSON(t, resp, &createdComment)
|
||||
|
@ -242,15 +242,15 @@ func TestAPICommentXRefAutoDate(t *testing.T) {
|
|||
assert.Equal(t, updatedAt.In(utcTZ), ref.UpdatedUnix.AsTimeInLocation(utcTZ))
|
||||
|
||||
// Remove the mention to issue #2 and check that the xref was neutered
|
||||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d?token=%s",
|
||||
repoOwner.Name, repo.Name, createdComment.ID, token)
|
||||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d",
|
||||
repoOwner.Name, repo.Name, createdComment.ID)
|
||||
|
||||
newCommentBody := "no mention"
|
||||
updatedAt = time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{
|
||||
Body: newCommentBody,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
@ -374,8 +374,8 @@ func TestAPIEditCommentWithDate(t *testing.T) {
|
|||
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
|
||||
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d?token=%s",
|
||||
repoOwner.Name, repo.Name, comment.ID, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d",
|
||||
repoOwner.Name, repo.Name, comment.ID)
|
||||
const newCommentBody = "This is the new comment body"
|
||||
|
||||
t.Run("WithAutoDate", func(t *testing.T) {
|
||||
|
@ -383,7 +383,7 @@ func TestAPIEditCommentWithDate(t *testing.T) {
|
|||
|
||||
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
|
||||
"body": newCommentBody,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
@ -405,7 +405,7 @@ func TestAPIEditCommentWithDate(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{
|
||||
Body: newCommentBody,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var updatedComment api.Comment
|
||||
DecodeJSON(t, resp, &updatedComment)
|
||||
|
|
|
@ -107,8 +107,8 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
|
|||
|
||||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets?token=%s",
|
||||
repoOwner.Name, repo.Name, issue.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets",
|
||||
repoOwner.Name, repo.Name, issue.Index)
|
||||
|
||||
filename := "image.png"
|
||||
buff := generateImg()
|
||||
|
@ -126,7 +126,7 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
|
|||
err = writer.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body)
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
|
||||
req.Header.Add("Content-Type", writer.FormDataContentType())
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
|
@ -147,7 +147,7 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
|
|||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
urlStr += fmt.Sprintf("&updated_at=%s", updatedAt.UTC().Format(time.RFC3339))
|
||||
urlStr += fmt.Sprintf("?updated_at=%s", updatedAt.UTC().Format(time.RFC3339))
|
||||
|
||||
// Setup multi-part
|
||||
writer := multipart.NewWriter(body)
|
||||
|
@ -158,7 +158,7 @@ func TestAPICreateIssueAttachmentAutoDate(t *testing.T) {
|
|||
err = writer.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body)
|
||||
req := NewRequestWithBody(t, "POST", urlStr, body).AddTokenAuth(token)
|
||||
req.Header.Add("Content-Type", writer.FormDataContentType())
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
|
|
|
@ -125,15 +125,15 @@ func TestAPIAddIssueLabelsAutoDate(t *testing.T) {
|
|||
|
||||
session := loginUser(t, owner.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels?token=%s",
|
||||
owner.Name, repo.Name, issueBefore.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels",
|
||||
owner.Name, repo.Name, issueBefore.Index)
|
||||
|
||||
t.Run("WithAutoDate", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
||||
Labels: []int64{1},
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
issueAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issueBefore.ID})
|
||||
|
@ -149,7 +149,7 @@ func TestAPIAddIssueLabelsAutoDate(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
||||
Labels: []int64{2},
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// dates will be converted into the same tz, in order to compare them
|
||||
|
|
|
@ -227,12 +227,12 @@ func TestAPIEditIssueAutoDate(t *testing.T) {
|
|||
// User2 is not owner, but can update the 'public' issue with auto date
|
||||
session := loginUser(t, "user2")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index)
|
||||
|
||||
body := "new content!"
|
||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Body: &body,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var apiIssue api.Issue
|
||||
DecodeJSON(t, resp, &apiIssue)
|
||||
|
@ -252,14 +252,14 @@ func TestAPIEditIssueAutoDate(t *testing.T) {
|
|||
// User1 is admin, and so can update the issue without auto date
|
||||
session := loginUser(t, "user1")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index)
|
||||
|
||||
body := "new content, with updated time"
|
||||
updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Body: &body,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusCreated)
|
||||
var apiIssue api.Issue
|
||||
DecodeJSON(t, resp, &apiIssue)
|
||||
|
@ -278,14 +278,14 @@ func TestAPIEditIssueAutoDate(t *testing.T) {
|
|||
// User2 is not owner nor admin, and so can't update the issue without auto date
|
||||
session := loginUser(t, "user2")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index)
|
||||
|
||||
body := "new content, with updated time"
|
||||
updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second)
|
||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Body: &body,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusForbidden)
|
||||
var apiError api.APIError
|
||||
DecodeJSON(t, resp, &apiError)
|
||||
|
@ -305,7 +305,7 @@ func TestAPIEditIssueMilestoneAutoDate(t *testing.T) {
|
|||
|
||||
session := loginUser(t, owner.Name)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index)
|
||||
|
||||
t.Run("WithAutoDate", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
@ -313,7 +313,7 @@ func TestAPIEditIssueMilestoneAutoDate(t *testing.T) {
|
|||
milestone := int64(1)
|
||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Milestone: &milestone,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// the execution of the API call supposedly lasted less than one minute
|
||||
|
@ -332,7 +332,7 @@ func TestAPIEditIssueMilestoneAutoDate(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Milestone: &milestone,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// the milestone date should be set to 'updatedAt'
|
||||
|
@ -353,7 +353,7 @@ func TestAPIEditIssueMilestoneAutoDate(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||
Milestone: &milestone,
|
||||
Updated: &updatedAt,
|
||||
})
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
// the milestone date should not change
|
||||
|
|
Loading…
Add table
Reference in a new issue