tercul-backend/internal/data/sql/monetization_repository_test.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- 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.
2025-12-27 00:33:34 +01:00

58 lines
1.6 KiB
Go

package sql_test
import (
"context"
"tercul/internal/data/sql"
"tercul/internal/domain"
"tercul/internal/platform/config"
"tercul/internal/testutil"
"testing"
"github.com/stretchr/testify/suite"
)
type MonetizationRepositoryTestSuite struct {
testutil.IntegrationTestSuite
MonetizationRepo domain.MonetizationRepository
}
func (s *MonetizationRepositoryTestSuite) SetupSuite() {
s.IntegrationTestSuite.SetupSuite(testutil.DefaultTestConfig())
cfg, err := config.LoadConfig()
s.Require().NoError(err)
s.MonetizationRepo = sql.NewMonetizationRepository(s.DB, cfg)
}
func (s *MonetizationRepositoryTestSuite) SetupTest() {
s.IntegrationTestSuite.SetupTest()
s.DB.Exec("DELETE FROM work_monetizations")
s.DB.Exec("DELETE FROM monetizations")
s.DB.Exec("DELETE FROM works")
}
func (s *MonetizationRepositoryTestSuite) TestAddMonetizationToWork() {
s.Run("should add a monetization to a work", func() {
// Arrange
work := s.CreateTestWork(s.AdminCtx, "Test Work", "en", "Test content")
monetization := &domain.Monetization{Amount: 10.0}
s.Require().NoError(s.DB.Create(monetization).Error)
// Act
err := s.MonetizationRepo.AddMonetizationToWork(context.Background(), work.ID, monetization.ID)
// Assert
s.Require().NoError(err)
// Verify that the association was created in the database
var foundWork domain.Work
err = s.DB.Preload("Monetizations").First(&foundWork, work.ID).Error
s.Require().NoError(err)
s.Require().Len(foundWork.Monetizations, 1)
s.Equal(monetization.ID, foundWork.Monetizations[0].ID)
})
}
func TestMonetizationRepository(t *testing.T) {
suite.Run(t, new(MonetizationRepositoryTestSuite))
}