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

72 lines
1.8KB

  1. package models
  2. import (
  3. "testing"
  4. "code.gitea.io/gitea/modules/timeutil"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestCancelStopwatch(t *testing.T) {
  8. assert.NoError(t, PrepareTestDatabase())
  9. user1, err := GetUserByID(1)
  10. assert.NoError(t, err)
  11. issue1, err := GetIssueByID(1)
  12. assert.NoError(t, err)
  13. issue2, err := GetIssueByID(2)
  14. assert.NoError(t, err)
  15. err = CancelStopwatch(user1, issue1)
  16. assert.NoError(t, err)
  17. AssertNotExistsBean(t, &Stopwatch{UserID: user1.ID, IssueID: issue1.ID})
  18. _ = AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeCancelTracking, PosterID: user1.ID, IssueID: issue1.ID})
  19. assert.Nil(t, CancelStopwatch(user1, issue2))
  20. }
  21. func TestStopwatchExists(t *testing.T) {
  22. assert.NoError(t, PrepareTestDatabase())
  23. assert.True(t, StopwatchExists(1, 1))
  24. assert.False(t, StopwatchExists(1, 2))
  25. }
  26. func TestHasUserStopwatch(t *testing.T) {
  27. assert.NoError(t, PrepareTestDatabase())
  28. exists, sw, err := HasUserStopwatch(1)
  29. assert.NoError(t, err)
  30. assert.True(t, exists)
  31. assert.Equal(t, int64(1), sw.ID)
  32. exists, _, err = HasUserStopwatch(3)
  33. assert.NoError(t, err)
  34. assert.False(t, exists)
  35. }
  36. func TestCreateOrStopIssueStopwatch(t *testing.T) {
  37. assert.NoError(t, PrepareTestDatabase())
  38. user2, err := GetUserByID(2)
  39. assert.NoError(t, err)
  40. user3, err := GetUserByID(3)
  41. assert.NoError(t, err)
  42. issue1, err := GetIssueByID(1)
  43. assert.NoError(t, err)
  44. issue2, err := GetIssueByID(2)
  45. assert.NoError(t, err)
  46. assert.NoError(t, CreateOrStopIssueStopwatch(user3, issue1))
  47. sw := AssertExistsAndLoadBean(t, &Stopwatch{UserID: 3, IssueID: 1}).(*Stopwatch)
  48. assert.Equal(t, true, sw.CreatedUnix <= timeutil.TimeStampNow())
  49. assert.NoError(t, CreateOrStopIssueStopwatch(user2, issue2))
  50. AssertNotExistsBean(t, &Stopwatch{UserID: 2, IssueID: 2})
  51. AssertExistsAndLoadBean(t, &TrackedTime{UserID: 2, IssueID: 2})
  52. }
上海开阖软件有限公司 沪ICP备12045867号-1