|
| 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 | + |
| 5 | +package models |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestCreateComment(t *testing.T) { |
| 15 | + assert.NoError(t, PrepareTestDatabase()) |
| 16 | + |
| 17 | + issue := AssertExistsAndLoadBean(t, &Issue{}).(*Issue) |
| 18 | + repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository) |
| 19 | + doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User) |
| 20 | + |
| 21 | + now := time.Now().Unix() |
| 22 | + comment, err := CreateComment(&CreateCommentOptions{ |
| 23 | + Type: CommentTypeComment, |
| 24 | + Doer: doer, |
| 25 | + Repo: repo, |
| 26 | + Issue: issue, |
| 27 | + Content: "Hello", |
| 28 | + }) |
| 29 | + assert.NoError(t, err) |
| 30 | + then := time.Now().Unix() |
| 31 | + |
| 32 | + assert.EqualValues(t, CommentTypeComment, comment.Type) |
| 33 | + assert.EqualValues(t, "Hello", comment.Content) |
| 34 | + assert.EqualValues(t, issue.ID, comment.IssueID) |
| 35 | + assert.EqualValues(t, doer.ID, comment.PosterID) |
| 36 | + AssertInt64InRange(t, now, then, comment.CreatedUnix) |
| 37 | + AssertExistsAndLoadBean(t, comment) // assert actually added to DB |
| 38 | + |
| 39 | + updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue) |
| 40 | + AssertInt64InRange(t, now, then, updatedIssue.UpdatedUnix) |
| 41 | +} |
0 commit comments