mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package repositories_test
|
|
|
|
import (
|
|
"context"
|
|
models2 "tercul/internal/models"
|
|
"tercul/internal/testutil"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
// WorkRepositorySuite is a test suite for the MockWorkRepository
|
|
type WorkRepositorySuite struct {
|
|
suite.Suite
|
|
repo *testutil.UnifiedMockWorkRepository
|
|
}
|
|
|
|
func (s *WorkRepositorySuite) SetupTest() {
|
|
s.repo = testutil.NewUnifiedMockWorkRepository()
|
|
}
|
|
|
|
func (s *WorkRepositorySuite) TestCreate() {
|
|
work := &models2.Work{Title: "Test Work"}
|
|
err := s.repo.Create(context.Background(), work)
|
|
s.Require().NoError(err)
|
|
}
|
|
|
|
func (s *WorkRepositorySuite) TestGetByID() {
|
|
work := &models2.Work{Title: "Test Work"}
|
|
s.repo.Create(context.Background(), work)
|
|
got, err := s.repo.GetByID(context.Background(), work.ID)
|
|
s.Require().NoError(err)
|
|
s.Require().Equal(work.ID, got.ID)
|
|
}
|
|
|
|
func (s *WorkRepositorySuite) TestFindByTitle() {
|
|
work := &models2.Work{Title: "Test"}
|
|
s.repo.Create(context.Background(), work)
|
|
works, err := s.repo.FindByTitle(context.Background(), "Test")
|
|
s.Require().NoError(err)
|
|
s.Require().Len(works, 1)
|
|
}
|
|
|
|
func (s *WorkRepositorySuite) TestFindByLanguage() {
|
|
work := &models2.Work{TranslatableModel: models2.TranslatableModel{Language: "en"}, Title: "Test"}
|
|
s.repo.Create(context.Background(), work)
|
|
result, err := s.repo.FindByLanguage(context.Background(), "en", 1, 10)
|
|
s.Require().NoError(err)
|
|
s.Require().Len(result.Items, 1)
|
|
}
|
|
|
|
func TestWorkRepositorySuite(t *testing.T) {
|
|
suite.Run(t, new(WorkRepositorySuite))
|
|
}
|