You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.4 KiB
66 lines
2.4 KiB
7 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package issues_test
|
||
7 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
3 years ago
|
|
||
7 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestCreateComment(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
3 years ago
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{}).(*issues_model.Issue)
|
||
3 years ago
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}).(*repo_model.Repository)
|
||
3 years ago
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
||
7 years ago
|
|
||
|
now := time.Now().Unix()
|
||
3 years ago
|
comment, err := issues_model.CreateComment(&issues_model.CreateCommentOptions{
|
||
|
Type: issues_model.CommentTypeComment,
|
||
7 years ago
|
Doer: doer,
|
||
|
Repo: repo,
|
||
|
Issue: issue,
|
||
|
Content: "Hello",
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
|
then := time.Now().Unix()
|
||
|
|
||
3 years ago
|
assert.EqualValues(t, issues_model.CommentTypeComment, comment.Type)
|
||
7 years ago
|
assert.EqualValues(t, "Hello", comment.Content)
|
||
|
assert.EqualValues(t, issue.ID, comment.IssueID)
|
||
|
assert.EqualValues(t, doer.ID, comment.PosterID)
|
||
3 years ago
|
unittest.AssertInt64InRange(t, now, then, int64(comment.CreatedUnix))
|
||
|
unittest.AssertExistsAndLoadBean(t, comment) // assert actually added to DB
|
||
7 years ago
|
|
||
3 years ago
|
updatedIssue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID}).(*issues_model.Issue)
|
||
3 years ago
|
unittest.AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
|
func TestFetchCodeComments(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
6 years ago
|
|
||
3 years ago
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}).(*issues_model.Issue)
|
||
3 years ago
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||
3 years ago
|
res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user)
|
||
6 years ago
|
assert.NoError(t, err)
|
||
|
assert.Contains(t, res, "README.md")
|
||
|
assert.Contains(t, res["README.md"], int64(4))
|
||
|
assert.Len(t, res["README.md"][4], 1)
|
||
|
assert.Equal(t, int64(4), res["README.md"][4][0].ID)
|
||
|
|
||
3 years ago
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||
3 years ago
|
res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2)
|
||
6 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, res, 1)
|
||
|
}
|