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

issue_user_test.go 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: 5,
  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 TestUpdateIssueUserByAssignee(t *testing.T) {
  27. assert.NoError(t, PrepareTestDatabase())
  28. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  29. // artificially change assignee in issue_user table
  30. AssertSuccessfulInsert(t, &IssueUser{IssueID: issue.ID, UID: 5, IsAssigned: true})
  31. _, err := x.Cols("is_assigned").
  32. Update(&IssueUser{IsAssigned: false}, &IssueUser{IssueID: issue.ID, UID: issue.AssigneeID})
  33. assert.NoError(t, err)
  34. assert.NoError(t, UpdateIssueUserByAssignee(issue))
  35. // issue_user table should now be correct again
  36. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: issue.AssigneeID}, "is_assigned=1")
  37. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 5}, "is_assigned=0")
  38. }
  39. func TestUpdateIssueUserByRead(t *testing.T) {
  40. assert.NoError(t, PrepareTestDatabase())
  41. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  42. assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
  43. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
  44. assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
  45. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
  46. assert.NoError(t, UpdateIssueUserByRead(NonexistentID, NonexistentID))
  47. }
  48. func TestUpdateIssueUsersByMentions(t *testing.T) {
  49. assert.NoError(t, PrepareTestDatabase())
  50. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  51. uids := []int64{2, 5}
  52. assert.NoError(t, UpdateIssueUsersByMentions(x, issue.ID, uids))
  53. for _, uid := range uids {
  54. AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: uid}, "is_mentioned=1")
  55. }
  56. }