mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit addresses several high-priority tasks from the TASKS.md file, including: - **Fix Background Job Panic:** Replaced `log.Fatalf` with `log.Printf` in the `asynq` server to prevent crashes. - **Refactor API Server Setup:** Consolidated the GraphQL Playground and Prometheus metrics endpoints into the main API server. - **Implement `DeleteUser` Mutation:** Implemented the `DeleteUser` resolver. - **Implement `CreateContribution` Mutation:** Implemented the `CreateContribution` resolver and its required application service. Additionally, this commit includes a major refactoring of the configuration management system to fix a broken build. The global `config.Cfg` variable has been removed and replaced with a dependency injection approach, where the configuration object is passed to all components that require it. This change has been applied across the entire codebase, including the test suite, to ensure a stable and testable application.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package sql_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"tercul/internal/data/sql"
|
|
"tercul/internal/domain"
|
|
workdomain "tercul/internal/domain/work"
|
|
"tercul/internal/platform/config"
|
|
"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())
|
|
cfg, err := config.LoadConfig()
|
|
s.Require().NoError(err)
|
|
s.MonetizationRepo = sql.NewMonetizationRepository(s.DB, cfg)
|
|
}
|
|
|
|
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))
|
|
} |