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

issue_stopwatch_test.go 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package models
  2. import (
  3. "testing"
  4. "time"
  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.Created.Before(time.Now()))
  49. assert.NoError(t, CreateOrStopIssueStopwatch(user2, issue2))
  50. AssertNotExistsBean(t, &Stopwatch{UserID: 2, IssueID: 2})
  51. AssertExistsAndLoadBean(t, &TrackedTime{UserID: 2, IssueID: 2})
  52. }