2017-02-02 13:33:36 +01:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-11 08:03:30 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2017-02-14 13:16:00 +01:00
|
|
|
|
2017-02-02 13:33:36 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-11-24 10:49:20 +01:00
|
|
|
func TestFollowUser(t *testing.T) {
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-24 10:49:20 +01:00
|
|
|
|
|
|
|
testSuccess := func(followerID, followedID int64) {
|
|
|
|
assert.NoError(t, user_model.FollowUser(followerID, followedID))
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
|
|
|
|
}
|
|
|
|
testSuccess(4, 2)
|
|
|
|
testSuccess(5, 2)
|
|
|
|
|
|
|
|
assert.NoError(t, user_model.FollowUser(2, 2))
|
|
|
|
|
|
|
|
unittest.CheckConsistencyFor(t, &user_model.User{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnfollowUser(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
|
|
|
testSuccess := func(followerID, followedID int64) {
|
|
|
|
assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
|
|
|
|
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
|
|
|
|
}
|
|
|
|
testSuccess(4, 2)
|
|
|
|
testSuccess(5, 2)
|
|
|
|
testSuccess(2, 2)
|
|
|
|
|
|
|
|
unittest.CheckConsistencyFor(t, &user_model.User{})
|
2021-09-24 13:32:56 +02:00
|
|
|
}
|