tercul-backend/internal/app/app.go
google-labs-jules[bot] 80cfe71e59 refactor: Refactor GraphQL tests to use mock-based unit tests
This commit refactors the GraphQL test suite to resolve persistent build failures and establish a stable, mock-based unit testing environment.

The key changes include:
- Consolidating all GraphQL test helper functions into a single, canonical file (`internal/adapters/graphql/graphql_test_utils_test.go`).
- Removing duplicated test helper code from `integration_test.go` and other test files.
- Creating a new, dedicated unit test file for the `like` and `unlike` mutations (`internal/adapters/graphql/like_resolvers_unit_test.go`) using a mock-based approach.
- Introducing mock services (`MockLikeService`, `MockAnalyticsService`) and updating mock repositories (`MockLikeRepository`, `MockWorkRepository`) in the `internal/testutil` package to support `testify/mock`.
- Adding a `ContextWithUserID` helper function to `internal/platform/auth/middleware.go` to facilitate testing of authenticated resolvers.

These changes resolve the `redeclared in this block` and package collision errors, resulting in a clean and passing test suite. This provides a solid foundation for future Test-Driven Development.
2025-10-03 09:21:41 +00:00

69 lines
2.3 KiB
Go

package app
import (
"tercul/internal/app/analytics"
"tercul/internal/app/author"
"tercul/internal/app/bookmark"
"tercul/internal/app/category"
"tercul/internal/app/collection"
"tercul/internal/app/comment"
"tercul/internal/app/like"
"tercul/internal/app/localization"
"tercul/internal/app/tag"
"tercul/internal/app/translation"
"tercul/internal/app/user"
"tercul/internal/app/auth"
"tercul/internal/app/work"
"tercul/internal/data/sql"
"tercul/internal/domain/search"
platform_auth "tercul/internal/platform/auth"
)
// Application is a container for all the application-layer services.
type Application struct {
Author *author.Service
Bookmark *bookmark.Service
Category *category.Service
Collection *collection.Service
Comment *comment.Service
Like *like.Service
Tag *tag.Service
Translation *translation.Service
User *user.Service
Localization *localization.Service
Auth *auth.Service
Work *work.Service
Analytics analytics.Service
}
func NewApplication(repos *sql.Repositories, searchClient search.SearchClient, analyticsService analytics.Service) *Application {
jwtManager := platform_auth.NewJWTManager()
authorService := author.NewService(repos.Author)
bookmarkService := bookmark.NewService(repos.Bookmark)
categoryService := category.NewService(repos.Category)
collectionService := collection.NewService(repos.Collection)
commentService := comment.NewService(repos.Comment)
likeService := like.NewService(repos.Like)
tagService := tag.NewService(repos.Tag)
translationService := translation.NewService(repos.Translation)
userService := user.NewService(repos.User)
localizationService := localization.NewService(repos.Localization)
authService := auth.NewService(repos.User, jwtManager)
workService := work.NewService(repos.Work, searchClient)
return &Application{
Author: authorService,
Bookmark: bookmarkService,
Category: categoryService,
Collection: collectionService,
Comment: commentService,
Like: likeService,
Tag: tagService,
Translation: translationService,
User: userService,
Localization: localizationService,
Auth: authService,
Work: workService,
Analytics: analyticsService,
}
}