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

user_follow_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package models
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestIsFollowing(t *testing.T) {
  7. assert.NoError(t, PrepareTestDatabase())
  8. assert.True(t, IsFollowing(4, 2))
  9. assert.False(t, IsFollowing(2, 4))
  10. assert.False(t, IsFollowing(5, NonexistentID))
  11. assert.False(t, IsFollowing(NonexistentID, 5))
  12. assert.False(t, IsFollowing(NonexistentID, NonexistentID))
  13. }
  14. func TestFollowUser(t *testing.T) {
  15. assert.NoError(t, PrepareTestDatabase())
  16. testSuccess := func(followerID, followedID int64) {
  17. assert.NoError(t, FollowUser(followerID, followedID))
  18. AssertExistsAndLoadBean(t, &Follow{UserID: followerID, FollowID: followedID})
  19. }
  20. testSuccess(4, 2)
  21. testSuccess(5, 2)
  22. assert.NoError(t, FollowUser(2, 2))
  23. CheckConsistencyFor(t, &User{})
  24. }
  25. func TestUnfollowUser(t *testing.T) {
  26. assert.NoError(t, PrepareTestDatabase())
  27. testSuccess := func(followerID, followedID int64) {
  28. assert.NoError(t, UnfollowUser(followerID, followedID))
  29. AssertNotExistsBean(t, &Follow{UserID: followerID, FollowID: followedID})
  30. }
  31. testSuccess(4, 2)
  32. testSuccess(5, 2)
  33. testSuccess(2, 2)
  34. CheckConsistencyFor(t, &User{})
  35. }