本站源代码
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.

62 lines
1.7KB

  1. // Copyright 2018 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. "github.com/stretchr/testify/assert"
  8. )
  9. func TestUpdateAssignee(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. // Fake issue with assignees
  12. issue, err := GetIssueWithAttrsByID(1)
  13. assert.NoError(t, err)
  14. // Assign multiple users
  15. user2, err := GetUserByID(2)
  16. assert.NoError(t, err)
  17. _, _, err = issue.ToggleAssignee(&User{ID: 1}, user2.ID)
  18. assert.NoError(t, err)
  19. user3, err := GetUserByID(3)
  20. assert.NoError(t, err)
  21. _, _, err = issue.ToggleAssignee(&User{ID: 1}, user3.ID)
  22. assert.NoError(t, err)
  23. user1, err := GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
  24. assert.NoError(t, err)
  25. _, _, err = issue.ToggleAssignee(&User{ID: 1}, user1.ID)
  26. assert.NoError(t, err)
  27. // Check if he got removed
  28. isAssigned, err := IsUserAssignedToIssue(issue, user1)
  29. assert.NoError(t, err)
  30. assert.False(t, isAssigned)
  31. // Check if they're all there
  32. assignees, err := GetAssigneesByIssue(issue)
  33. assert.NoError(t, err)
  34. var expectedAssignees []*User
  35. expectedAssignees = append(expectedAssignees, user2, user3)
  36. for in, assignee := range assignees {
  37. assert.Equal(t, assignee.ID, expectedAssignees[in].ID)
  38. }
  39. // Check if the user is assigned
  40. isAssigned, err = IsUserAssignedToIssue(issue, user2)
  41. assert.NoError(t, err)
  42. assert.True(t, isAssigned)
  43. // This user should not be assigned
  44. isAssigned, err = IsUserAssignedToIssue(issue, &User{ID: 4})
  45. assert.NoError(t, err)
  46. assert.False(t, isAssigned)
  47. }
上海开阖软件有限公司 沪ICP备12045867号-1