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.

49 lines
1.3 KiB

  1. // Copyright 2020 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 TestIsFollowing(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. assert.True(t, IsFollowing(4, 2))
  12. assert.False(t, IsFollowing(2, 4))
  13. assert.False(t, IsFollowing(5, NonexistentID))
  14. assert.False(t, IsFollowing(NonexistentID, 5))
  15. assert.False(t, IsFollowing(NonexistentID, NonexistentID))
  16. }
  17. func TestFollowUser(t *testing.T) {
  18. assert.NoError(t, PrepareTestDatabase())
  19. testSuccess := func(followerID, followedID int64) {
  20. assert.NoError(t, FollowUser(followerID, followedID))
  21. AssertExistsAndLoadBean(t, &Follow{UserID: followerID, FollowID: followedID})
  22. }
  23. testSuccess(4, 2)
  24. testSuccess(5, 2)
  25. assert.NoError(t, FollowUser(2, 2))
  26. CheckConsistencyFor(t, &User{})
  27. }
  28. func TestUnfollowUser(t *testing.T) {
  29. assert.NoError(t, PrepareTestDatabase())
  30. testSuccess := func(followerID, followedID int64) {
  31. assert.NoError(t, UnfollowUser(followerID, followedID))
  32. AssertNotExistsBean(t, &Follow{UserID: followerID, FollowID: followedID})
  33. }
  34. testSuccess(4, 2)
  35. testSuccess(5, 2)
  36. testSuccess(2, 2)
  37. CheckConsistencyFor(t, &User{})
  38. }