test: expand test coverage across diary, product, savedrecipe, ingredient, menu, recognition
- Fix locale_test: add TestMain to pre-populate Supported map so zh/es tests pass - Export pure functions for testability: ResolveWeekStart, MapCuisineSlug (menu + savedrecipe), MergeAndDeduplicate - Introduce repository interfaces (DiaryRepository, ProductRepository, SavedRecipeRepository, IngredientSearcher) in each handler; NewHandler now accepts interfaces — concrete *Repository still satisfies them - Add mock files: diary/mocks, product/mocks, savedrecipe/mocks - Add handler unit tests (no DB) for diary (8), product (8), savedrecipe (8), ingredient (5) - Add pure-function unit tests: menu/ResolveWeekStart (6), savedrecipe/MapCuisineSlug (5), recognition/MergeAndDeduplicate (6) - Add repository integration tests (//go:build integration): diary (4), product (6) - Extend recipe integration tests: GetByID_Found, GetByID_WithTranslation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
26
backend/internal/domain/diary/mocks/repository.go
Normal file
26
backend/internal/domain/diary/mocks/repository.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/food-ai/backend/internal/domain/diary"
|
||||
)
|
||||
|
||||
// MockDiaryRepository is a test double implementing diary.DiaryRepository.
|
||||
type MockDiaryRepository struct {
|
||||
ListByDateFn func(ctx context.Context, userID, date string) ([]*diary.Entry, error)
|
||||
CreateFn func(ctx context.Context, userID string, req diary.CreateRequest) (*diary.Entry, error)
|
||||
DeleteFn func(ctx context.Context, id, userID string) error
|
||||
}
|
||||
|
||||
func (m *MockDiaryRepository) ListByDate(ctx context.Context, userID, date string) ([]*diary.Entry, error) {
|
||||
return m.ListByDateFn(ctx, userID, date)
|
||||
}
|
||||
|
||||
func (m *MockDiaryRepository) Create(ctx context.Context, userID string, req diary.CreateRequest) (*diary.Entry, error) {
|
||||
return m.CreateFn(ctx, userID, req)
|
||||
}
|
||||
|
||||
func (m *MockDiaryRepository) Delete(ctx context.Context, id, userID string) error {
|
||||
return m.DeleteFn(ctx, id, userID)
|
||||
}
|
||||
Reference in New Issue
Block a user