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:
dbastrikin
2026-03-15 22:54:09 +02:00
parent 7c338c35f3
commit bfaca1a2c1
21 changed files with 1452 additions and 28 deletions

View File

@@ -3,11 +3,21 @@ package locale_test
import (
"context"
"net/http"
"os"
"testing"
"github.com/food-ai/backend/internal/infra/locale"
)
func TestMain(m *testing.M) {
// Populate Supported map with all known languages before running tests.
// In production this is done by locale.LoadFromDB at startup.
for _, code := range []string{"en", "ru", "es", "de", "fr", "it", "pt", "zh", "ja", "ko", "ar", "hi"} {
locale.Supported[code] = true
}
os.Exit(m.Run())
}
func TestParse(t *testing.T) {
tests := []struct {
name string