mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
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.
40 lines
921 B
Go
40 lines
921 B
Go
package trending
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"tercul/internal/app/analytics"
|
|
|
|
"github.com/hibiken/asynq"
|
|
)
|
|
|
|
const (
|
|
TaskUpdateTrending = "task:trending:update"
|
|
)
|
|
|
|
type UpdateTrendingPayload struct {
|
|
// No payload needed for now
|
|
}
|
|
|
|
func NewUpdateTrendingTask() (*asynq.Task, error) {
|
|
payload, err := json.Marshal(UpdateTrendingPayload{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return asynq.NewTask(TaskUpdateTrending, payload), nil
|
|
}
|
|
|
|
func HandleUpdateTrendingTask(analyticsService analytics.Service) asynq.HandlerFunc {
|
|
return func(ctx context.Context, t *asynq.Task) error {
|
|
var p UpdateTrendingPayload
|
|
if err := json.Unmarshal(t.Payload(), &p); err != nil {
|
|
return err
|
|
}
|
|
return analyticsService.UpdateTrending(ctx)
|
|
}
|
|
}
|
|
|
|
func RegisterTrendingHandlers(mux *asynq.ServeMux, analyticsService analytics.Service) {
|
|
mux.HandleFunc(TaskUpdateTrending, HandleUpdateTrendingTask(analyticsService))
|
|
}
|