本站源代码
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.

46 lines
1.1KB

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1