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.

41 lines
1.2 KiB

  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, int64(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, int64(updatedIssue.UpdatedUnix))
  33. }