Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 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/unittest"
  8. user_model "code.gitea.io/gitea/models/user"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestFollowUser(t *testing.T) {
  12. assert.NoError(t, unittest.PrepareTestDatabase())
  13. testSuccess := func(followerID, followedID int64) {
  14. assert.NoError(t, user_model.FollowUser(followerID, followedID))
  15. unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
  16. }
  17. testSuccess(4, 2)
  18. testSuccess(5, 2)
  19. assert.NoError(t, user_model.FollowUser(2, 2))
  20. unittest.CheckConsistencyFor(t, &user_model.User{})
  21. }
  22. func TestUnfollowUser(t *testing.T) {
  23. assert.NoError(t, unittest.PrepareTestDatabase())
  24. testSuccess := func(followerID, followedID int64) {
  25. assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
  26. unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
  27. }
  28. testSuccess(4, 2)
  29. testSuccess(5, 2)
  30. testSuccess(2, 2)
  31. unittest.CheckConsistencyFor(t, &user_model.User{})
  32. }