fix: add missing method to mock

This commit is contained in:
2025-11-21 17:07:22 +01:00
parent 4b04461ebb
commit fea49fad8d

View File

@@ -7,9 +7,10 @@ import (
"sync" "sync"
"testing" "testing"
"gorm.io/gorm"
"goyco/internal/database" "goyco/internal/database"
"goyco/internal/repositories" "goyco/internal/repositories"
"gorm.io/gorm"
) )
type mockVoteRepo struct { type mockVoteRepo struct {
@@ -240,6 +241,25 @@ func (m *mockVoteRepo) CountByUserID(userID uint) (int64, error) {
return count, nil return count, nil
} }
func (m *mockVoteRepo) GetVoteCountsByPostID(postID uint) (int, int, error) {
m.mu.RLock()
defer m.mu.RUnlock()
upVotes := 0
downVotes := 0
for _, vote := range m.votes {
if vote.PostID == postID {
switch vote.Type {
case database.VoteUp:
upVotes++
case database.VoteDown:
downVotes++
}
}
}
return upVotes, downVotes, nil
}
func (m *mockVoteRepo) WithTx(tx *gorm.DB) repositories.VoteRepository { func (m *mockVoteRepo) WithTx(tx *gorm.DB) repositories.VoteRepository {
return m return m
} }