mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
Some checks failed
- Updated database models and repositories to replace uint IDs with UUIDs. - Modified test fixtures to generate and use UUIDs for authors, translations, users, and works. - Adjusted mock implementations to align with the new UUID structure. - Ensured all relevant functions and methods are updated to handle UUIDs correctly. - Added necessary imports for UUID handling in various files.
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package translation
|
|
|
|
import (
|
|
"context"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
"tercul/internal/domain"
|
|
"testing"
|
|
)
|
|
|
|
type TranslationQueriesSuite struct {
|
|
suite.Suite
|
|
repo *mockTranslationRepository
|
|
queries *TranslationQueries
|
|
}
|
|
|
|
func (s *TranslationQueriesSuite) SetupTest() {
|
|
s.repo = &mockTranslationRepository{}
|
|
s.queries = NewTranslationQueries(s.repo)
|
|
}
|
|
|
|
func TestTranslationQueriesSuite(t *testing.T) {
|
|
suite.Run(t, new(TranslationQueriesSuite))
|
|
}
|
|
|
|
func (s *TranslationQueriesSuite) TestTranslation_Success() {
|
|
translation := &domain.Translation{
|
|
BaseModel: domain.BaseModel{ID: 1},
|
|
Title: "Test Translation",
|
|
Language: "es",
|
|
Content: "Test content",
|
|
TranslatableID: 1,
|
|
}
|
|
s.repo.getByIDFunc = func(ctx context.Context, id uint) (*domain.Translation, error) {
|
|
return translation, nil
|
|
}
|
|
dto, err := s.queries.Translation(context.Background(), 1)
|
|
assert.NoError(s.T(), err)
|
|
|
|
expectedDTO := &TranslationDTO{
|
|
ID: 1,
|
|
Title: "Test Translation",
|
|
Language: "es",
|
|
Content: "Test content",
|
|
TranslatableID: 1,
|
|
}
|
|
assert.Equal(s.T(), expectedDTO, dto)
|
|
}
|
|
|
|
func (s *TranslationQueriesSuite) TestListTranslations_Success() {
|
|
domainTranslations := &domain.PaginatedResult[domain.Translation]{
|
|
Items: []domain.Translation{
|
|
{BaseModel: domain.BaseModel{ID: 1}, Title: "Translation 1", Language: "es", Content: "Content 1", TranslatableID: 1},
|
|
{BaseModel: domain.BaseModel{ID: 2}, Title: "Translation 2", Language: "fr", Content: "Content 2", TranslatableID: 1},
|
|
},
|
|
TotalCount: 2,
|
|
Page: 1,
|
|
PageSize: 10,
|
|
TotalPages: 1,
|
|
}
|
|
s.repo.listByWorkIDPaginatedFunc = func(ctx context.Context, workID uint, language *string, page, pageSize int) (*domain.PaginatedResult[domain.Translation], error) {
|
|
return domainTranslations, nil
|
|
}
|
|
|
|
paginatedDTOs, err := s.queries.ListTranslations(context.Background(), 1, nil, 1, 10)
|
|
assert.NoError(s.T(), err)
|
|
|
|
expectedDTOs := &domain.PaginatedResult[TranslationDTO]{
|
|
Items: []TranslationDTO{
|
|
{ID: 1, Title: "Translation 1", Language: "es", Content: "Content 1", TranslatableID: 1},
|
|
{ID: 2, Title: "Translation 2", Language: "fr", Content: "Content 2", TranslatableID: 1},
|
|
},
|
|
TotalCount: 2,
|
|
Page: 1,
|
|
PageSize: 10,
|
|
TotalPages: 1,
|
|
}
|
|
assert.Equal(s.T(), expectedDTOs, paginatedDTOs)
|
|
}
|