Skip to content

Commit ade96b7

Browse files
committed
Move some tests in models
1 parent 40f054a commit ade96b7

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

models/user/main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ func TestMain(m *testing.M) {
1717
"user_redirect.yml",
1818
"follow.yml",
1919
"user_open_id.yml",
20+
"two_factor.yml",
21+
"oauth2_application.yml",
22+
"user.yml",
2023
)
2124
}

models/user/user_test.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestSearchUsers(t *testing.T) {
6060
testSuccess := func(opts *SearchUserOptions, expectedUserOrOrgIDs []int64) {
6161
users, _, err := SearchUsers(opts)
6262
assert.NoError(t, err)
63-
if assert.Len(t, users, len(expectedUserOrOrgIDs)) {
63+
if assert.Len(t, users, len(expectedUserOrOrgIDs), opts) {
6464
for i, expectedID := range expectedUserOrOrgIDs {
6565
assert.EqualValues(t, expectedID, users[i].ID)
6666
}
@@ -335,35 +335,6 @@ func TestNewUserRedirect3(t *testing.T) {
335335
})
336336
}
337337

338-
func TestFollowUser(t *testing.T) {
339-
assert.NoError(t, unittest.PrepareTestDatabase())
340-
341-
testSuccess := func(followerID, followedID int64) {
342-
assert.NoError(t, FollowUser(followerID, followedID))
343-
unittest.AssertExistsAndLoadBean(t, &Follow{UserID: followerID, FollowID: followedID})
344-
}
345-
testSuccess(4, 2)
346-
testSuccess(5, 2)
347-
348-
assert.NoError(t, FollowUser(2, 2))
349-
350-
unittest.CheckConsistencyFor(t, &User{})
351-
}
352-
353-
func TestUnfollowUser(t *testing.T) {
354-
assert.NoError(t, unittest.PrepareTestDatabase())
355-
356-
testSuccess := func(followerID, followedID int64) {
357-
assert.NoError(t, UnfollowUser(followerID, followedID))
358-
unittest.AssertNotExistsBean(t, &Follow{UserID: followerID, FollowID: followedID})
359-
}
360-
testSuccess(4, 2)
361-
testSuccess(5, 2)
362-
testSuccess(2, 2)
363-
364-
unittest.CheckConsistencyFor(t, &User{})
365-
}
366-
367338
func TestGetUserByOpenID(t *testing.T) {
368339
assert.NoError(t, unittest.PrepareTestDatabase())
369340

models/user_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ import (
1515
"github.com/stretchr/testify/assert"
1616
)
1717

18+
func TestFollowUser(t *testing.T) {
19+
assert.NoError(t, unittest.PrepareTestDatabase())
20+
21+
testSuccess := func(followerID, followedID int64) {
22+
assert.NoError(t, user_model.FollowUser(followerID, followedID))
23+
unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
24+
}
25+
testSuccess(4, 2)
26+
testSuccess(5, 2)
27+
28+
assert.NoError(t, user_model.FollowUser(2, 2))
29+
30+
unittest.CheckConsistencyFor(t, &user_model.User{})
31+
}
32+
33+
func TestUnfollowUser(t *testing.T) {
34+
assert.NoError(t, unittest.PrepareTestDatabase())
35+
36+
testSuccess := func(followerID, followedID int64) {
37+
assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
38+
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
39+
}
40+
testSuccess(4, 2)
41+
testSuccess(5, 2)
42+
testSuccess(2, 2)
43+
44+
unittest.CheckConsistencyFor(t, &user_model.User{})
45+
}
46+
1847
func TestUserIsPublicMember(t *testing.T) {
1948
assert.NoError(t, unittest.PrepareTestDatabase())
2049

0 commit comments

Comments
 (0)