mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit isolates the `Work` aggregate into its own package at `internal/domain/work`, following the first step of the refactoring plan in `refactor.md`. - The `Work` struct, related types, and the `WorkRepository` interface have been moved to the new package. - A circular dependency between `domain` and `work` was resolved by moving the `AnalyticsRepository` to the `app` layer. - All references to the moved types have been updated across the entire codebase to fix compilation errors. - Test files, including mocks and integration tests, have been updated to reflect the new structure.
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package sql_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"tercul/internal/data/sql"
|
|
"tercul/internal/domain"
|
|
workdomain "tercul/internal/domain/work"
|
|
"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 workdomain.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))
|
|
} |