clean: remove unused duplicate functions that are already implemented/used in repositories/fixtures.go
This commit is contained in:
@@ -6,9 +6,10 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"goyco/internal/database"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"goyco/internal/database"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestConfig struct {
|
type TestConfig struct {
|
||||||
@@ -365,88 +366,3 @@ func CleanupTestData(t *testing.T, db *gorm.DB) {
|
|||||||
t.Logf("Warning: Failed to clean up users: %v", err)
|
t.Logf("Warning: Failed to clean up users: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssertUserExists(t *testing.T, db *gorm.DB, userID uint) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.User{}).Where("id = ?", userID).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to check user existence: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if count == 0 {
|
|
||||||
t.Errorf("Expected user with ID %d to exist", userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func AssertUserNotExists(t *testing.T, db *gorm.DB, userID uint) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.User{}).Where("id = ?", userID).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to check user existence: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if count > 0 {
|
|
||||||
t.Errorf("Expected user with ID %d to not exist", userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func AssertPostExists(t *testing.T, db *gorm.DB, postID uint) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.Post{}).Where("id = ?", postID).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to check post existence: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if count == 0 {
|
|
||||||
t.Errorf("Expected post with ID %d to exist", postID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func AssertVoteExists(t *testing.T, db *gorm.DB, userID, postID uint) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.Vote{}).Where("user_id = ? AND post_id = ?", userID, postID).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to check vote existence: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if count == 0 {
|
|
||||||
t.Errorf("Expected vote for user %d and post %d to exist", userID, postID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUserCount(t *testing.T, db *gorm.DB) int64 {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.User{}).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to get user count: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPostCount(t *testing.T, db *gorm.DB) int64 {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.Post{}).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to get post count: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVoteCount(t *testing.T, db *gorm.DB) int64 {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
if err := db.Model(&database.Vote{}).Count(&count).Error; err != nil {
|
|
||||||
t.Fatalf("Failed to get vote count: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user