tercul-backend/internal/data/sql/monetization_repository_test.go
google-labs-jules[bot] 85f052b2d6 refactor: Align codebase with DDD architecture to fix build
This commit addresses a broken build state caused by a mid-stream architectural refactoring. The changes align the existing code with the new Domain-Driven Design (DDD-lite) structure outlined in `refactor.md`.

Key changes include:
- Defined missing domain interfaces for `Auth`, `Localization`, and `Search`.
- Refactored application services to use a `Commands` and `Queries` pattern.
- Updated GraphQL resolvers to call application services instead of accessing repositories directly.
- Fixed dependency injection in `cmd/api/main.go` by removing the non-existent `ApplicationBuilder` and manually instantiating services.
- Corrected numerous test files (`integration`, `unit`, and `repository` tests) to reflect the new architecture, including fixing mock objects and test suite setups.
- Added missing database migrations for test schemas to resolve "no such table" errors.

This effort successfully gets the application to a compilable state and passes a significant portion of the test suite, laying the groundwork for further development and fixing the remaining test failures.
2025-10-03 01:17:53 +00:00

54 lines
1.5 KiB
Go

package sql_test
import (
"context"
"testing"
"tercul/internal/data/sql"
"tercul/internal/domain"
"tercul/internal/testutil"
"github.com/stretchr/testify/suite"
)
type MonetizationRepositoryTestSuite struct {
testutil.IntegrationTestSuite
MonetizationRepo domain.MonetizationRepository
}
func (s *MonetizationRepositoryTestSuite) SetupSuite() {
s.IntegrationTestSuite.SetupSuite(testutil.DefaultTestConfig())
s.MonetizationRepo = sql.NewMonetizationRepository(s.DB)
}
func (s *MonetizationRepositoryTestSuite) 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("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))
}