Files
food-ai/backend/tests/savedrecipe/map_cuisine_slug_test.go
dbastrikin bfaca1a2c1 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>
2026-03-15 22:54:09 +02:00

72 lines
1.8 KiB
Go

package savedrecipe_test
import (
"testing"
"github.com/food-ai/backend/internal/domain/savedrecipe"
)
func TestMapCuisineSlug_KnownCuisines(t *testing.T) {
tests := []struct {
input string
want string
}{
{"italian", "italian"},
{"french", "french"},
{"russian", "russian"},
{"chinese", "chinese"},
{"japanese", "japanese"},
{"korean", "korean"},
{"mexican", "mexican"},
{"mediterranean", "mediterranean"},
{"indian", "indian"},
{"thai", "thai"},
{"american", "american"},
{"georgian", "georgian"},
{"spanish", "spanish"},
{"german", "german"},
{"middle_eastern", "middle_eastern"},
{"turkish", "turkish"},
{"greek", "greek"},
{"vietnamese", "vietnamese"},
}
for _, tc := range tests {
result := savedrecipe.MapCuisineSlug(tc.input)
if result != tc.want {
t.Errorf("MapCuisineSlug(%q) = %q, want %q", tc.input, result, tc.want)
}
}
}
func TestMapCuisineSlug_GenericFallsToOther(t *testing.T) {
for _, input := range []string{"asian", "european"} {
result := savedrecipe.MapCuisineSlug(input)
if result != "other" {
t.Errorf("MapCuisineSlug(%q) = %q, want %q", input, result, "other")
}
}
}
func TestMapCuisineSlug_Unknown(t *testing.T) {
result := savedrecipe.MapCuisineSlug("peruvian")
if result != "other" {
t.Errorf("MapCuisineSlug(peruvian) = %q, want %q", result, "other")
}
}
func TestMapCuisineSlug_Empty(t *testing.T) {
result := savedrecipe.MapCuisineSlug("")
if result != "other" {
t.Errorf("MapCuisineSlug() = %q, want %q", result, "other")
}
}
func TestMapCuisineSlug_CaseSensitive(t *testing.T) {
// The function does NOT lowercase — "ITALIAN" is unknown and falls back to "other".
result := savedrecipe.MapCuisineSlug("ITALIAN")
if result != "other" {
t.Errorf("MapCuisineSlug(ITALIAN) = %q, want %q", result, "other")
}
}