Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 02:36:10 +01:00

test POST /{username}/{reponame}/{type:issues|pulls}/{index}/content-history/soft-delete

This commit is contained in:
Loïc Dachary 2023-11-12 15:12:57 +01:00
parent 72e7769a5c
commit 6edae51a23
No known key found for this signature in database
GPG key ID: 992D23B392F9E4F2
2 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1 @@
[] # empty

View file

@ -306,6 +306,73 @@ func TestIssueCommentUpdate(t *testing.T) {
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: commentID})
assert.Equal(t, modifiedContent, comment.Content)
historyBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{CommentID: commentID})
assert.Equal(t, comment1, historyBefore.ContentText)
assert.False(t, historyBefore.IsDeleted)
softDelete := fmt.Sprintf("content-history/soft-delete?comment_id=%d&history_id=%d", commentID, historyBefore.ID)
// Using the ID of a comment that does not belong to the repository must fail
{
session5 := loginUser(t, "user5")
otherIssueURL := testNewIssue(t, session5, "user5", "repo4", "Other Title", "Other Description")
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/%s", otherIssueURL, softDelete), map[string]string{
"_csrf": GetCSRF(t, session5, otherIssueURL),
})
session5.MakeRequest(t, req, http.StatusNotFound)
}
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/%s", issueURL, softDelete), map[string]string{
"_csrf": GetCSRF(t, session, issueURL),
})
session.MakeRequest(t, req, http.StatusOK)
historyAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{ID: historyBefore.ID})
assert.True(t, historyAfter.IsDeleted)
}
func TestIssueContentUpdate(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
content1 := "Content one"
issueURL, issue := testIssueWithBean(t, "user2", 1, "Title", content1)
modifiedContent := content1 + "MODIFIED"
req := NewRequestWithValues(t, "POST", fmt.Sprintf("%s/content", issueURL), map[string]string{
"_csrf": GetCSRF(t, session, issueURL),
"content": modifiedContent,
})
session.MakeRequest(t, req, http.StatusOK)
issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID})
assert.Equal(t, modifiedContent, issue.Content)
historyBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{IssueID: issue.ID})
assert.Equal(t, content1, historyBefore.ContentText)
assert.False(t, historyBefore.IsDeleted)
softDelete := fmt.Sprintf("content-history/soft-delete?history_id=%d", historyBefore.ID)
// Using the ID of a comment that does not belong to the repository must fail
session5 := loginUser(t, "user5")
otherIssueURL := testNewIssue(t, session5, "user5", "repo4", "Other Title", "Other Description")
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/%s", otherIssueURL, softDelete), map[string]string{
"_csrf": GetCSRF(t, session5, otherIssueURL),
})
session5.MakeRequest(t, req, http.StatusNotFound)
historyIdentical := unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{ID: historyBefore.ID})
assert.Equal(t, content1, historyIdentical.ContentText)
assert.False(t, historyIdentical.IsDeleted)
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/%s", issueURL, softDelete), map[string]string{
"_csrf": GetCSRF(t, session, issueURL),
})
session.MakeRequest(t, req, http.StatusOK)
historyAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{ID: historyBefore.ID})
assert.True(t, historyAfter.IsDeleted)
}
func TestIssueReaction(t *testing.T) {