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.3KB

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