1
0
Fork 0
forked from forgejo/forgejo

[FEAT] allow setting the update date on issues and comments (squash) do not use token= query param

See 33439b733a
This commit is contained in:
Earl Warren 2023-12-25 12:29:23 +01:00
parent 868b7a436f
commit c5139a75b9
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
5 changed files with 44 additions and 44 deletions

View file

@ -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)