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.

user_follow_test.go 1.4KB

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