Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

issue_comment_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestCreateComment(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. issue := AssertExistsAndLoadBean(t, &Issue{}).(*Issue)
  13. repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
  14. doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
  15. now := time.Now().Unix()
  16. comment, err := CreateComment(&CreateCommentOptions{
  17. Type: CommentTypeComment,
  18. Doer: doer,
  19. Repo: repo,
  20. Issue: issue,
  21. Content: "Hello",
  22. })
  23. assert.NoError(t, err)
  24. then := time.Now().Unix()
  25. assert.EqualValues(t, CommentTypeComment, comment.Type)
  26. assert.EqualValues(t, "Hello", comment.Content)
  27. assert.EqualValues(t, issue.ID, comment.IssueID)
  28. assert.EqualValues(t, doer.ID, comment.PosterID)
  29. AssertInt64InRange(t, now, then, comment.CreatedUnix)
  30. AssertExistsAndLoadBean(t, comment) // assert actually added to DB
  31. updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
  32. AssertInt64InRange(t, now, then, updatedIssue.UpdatedUnix)
  33. }