mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
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.
69 lines
1.5 KiB
Go
69 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 BookRepositoryTestSuite struct {
|
|
testutil.IntegrationTestSuite
|
|
BookRepo domain.BookRepository
|
|
}
|
|
|
|
func (s *BookRepositoryTestSuite) SetupSuite() {
|
|
s.IntegrationTestSuite.SetupSuite(testutil.DefaultTestConfig())
|
|
s.BookRepo = sql.NewBookRepository(s.DB)
|
|
}
|
|
|
|
func (s *BookRepositoryTestSuite) SetupTest() {
|
|
s.DB.Exec("DELETE FROM books")
|
|
}
|
|
|
|
func (s *BookRepositoryTestSuite) createBook(title, isbn string) *domain.Book {
|
|
book := &domain.Book{
|
|
Title: title,
|
|
ISBN: isbn,
|
|
TranslatableModel: domain.TranslatableModel{
|
|
Language: "en",
|
|
},
|
|
}
|
|
err := s.BookRepo.Create(context.Background(), book)
|
|
s.Require().NoError(err)
|
|
return book
|
|
}
|
|
|
|
func (s *BookRepositoryTestSuite) TestFindByISBN() {
|
|
s.Run("should return a book by ISBN", func() {
|
|
// Arrange
|
|
s.createBook("Test Book", "1234567890")
|
|
|
|
// Act
|
|
foundBook, err := s.BookRepo.FindByISBN(context.Background(), "1234567890")
|
|
|
|
// Assert
|
|
s.Require().NoError(err)
|
|
s.Require().NotNil(foundBook)
|
|
s.Equal("Test Book", foundBook.Title)
|
|
})
|
|
|
|
s.Run("should return error if ISBN not found", func() {
|
|
// Arrange
|
|
s.createBook("Another Book", "1111111111")
|
|
|
|
// Act
|
|
_, err := s.BookRepo.FindByISBN(context.Background(), "9999999999")
|
|
|
|
// Assert
|
|
s.Require().Error(err)
|
|
})
|
|
}
|
|
|
|
func TestBookRepository(t *testing.T) {
|
|
suite.Run(t, new(BookRepositoryTestSuite))
|
|
}
|