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.

57 lines
1.7 KiB

  1. // Copyright 2017 The Gogs 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. "github.com/stretchr/testify/assert"
  8. )
  9. func Test_newIssueUsers(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  12. newIssue := &Issue{
  13. RepoID: repo.ID,
  14. PosterID: 4,
  15. Index: 6,
  16. Title: "newTestIssueTitle",
  17. Content: "newTestIssueContent",
  18. }
  19. // artificially insert new issue
  20. AssertSuccessfulInsert(t, newIssue)
  21. assert.NoError(t, newIssueUsers(x, repo, newIssue))
  22. // issue_user table should now have entries for new issue
  23. AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: newIssue.PosterID})
  24. AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: repo.OwnerID})
  25. }
  26. func TestUpdateIssueUserByRead(t *testing.T) {
  27. assert.NoError(t, PrepareTestDatabase())
  28. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  29. assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
  30. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
  31. assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
  32. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
  33. assert.NoError(t, UpdateIssueUserByRead(NonexistentID, NonexistentID))
  34. }
  35. func TestUpdateIssueUsersByMentions(t *testing.T) {
  36. assert.NoError(t, PrepareTestDatabase())
  37. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  38. uids := []int64{2, 5}
  39. assert.NoError(t, UpdateIssueUsersByMentions(DefaultDBContext(), issue.ID, uids))
  40. for _, uid := range uids {
  41. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: uid}, "is_mentioned=1")
  42. }
  43. }