- 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>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package menu_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/food-ai/backend/internal/domain/menu"
|
|
)
|
|
|
|
func TestResolveWeekStart_ValidFormat(t *testing.T) {
|
|
// ISO week 1 of 2026 starts on Monday 2025-12-29
|
|
result, resolveError := menu.ResolveWeekStart("2026-W01")
|
|
if resolveError != nil {
|
|
t.Fatalf("unexpected error: %v", resolveError)
|
|
}
|
|
if result != "2025-12-29" {
|
|
t.Errorf("ResolveWeekStart(2026-W01) = %q, want %q", result, "2025-12-29")
|
|
}
|
|
}
|
|
|
|
func TestResolveWeekStart_Week10(t *testing.T) {
|
|
// Week 10 of 2026 starts on Monday 2026-03-02
|
|
result, resolveError := menu.ResolveWeekStart("2026-W10")
|
|
if resolveError != nil {
|
|
t.Fatalf("unexpected error: %v", resolveError)
|
|
}
|
|
if result != "2026-03-02" {
|
|
t.Errorf("ResolveWeekStart(2026-W10) = %q, want %q", result, "2026-03-02")
|
|
}
|
|
}
|
|
|
|
func TestResolveWeekStart_InvalidFormat(t *testing.T) {
|
|
_, resolveError := menu.ResolveWeekStart("2026-01-05")
|
|
if resolveError == nil {
|
|
t.Fatal("expected error for date format input, got nil")
|
|
}
|
|
}
|
|
|
|
func TestResolveWeekStart_InvalidWeekNum(t *testing.T) {
|
|
_, resolveError := menu.ResolveWeekStart("2026-W99")
|
|
if resolveError == nil {
|
|
t.Fatal("expected error for week 99, got nil")
|
|
}
|
|
}
|
|
|
|
func TestResolveWeekStart_WeekZero(t *testing.T) {
|
|
_, resolveError := menu.ResolveWeekStart("2026-W00")
|
|
if resolveError == nil {
|
|
t.Fatal("expected error for week 0, got nil")
|
|
}
|
|
}
|
|
|
|
func TestResolveWeekStart_EmptyReturnsCurrentMonday(t *testing.T) {
|
|
// Empty string should return current week's Monday without error.
|
|
result, resolveError := menu.ResolveWeekStart("")
|
|
if resolveError != nil {
|
|
t.Fatalf("unexpected error: %v", resolveError)
|
|
}
|
|
if len(result) != 10 {
|
|
t.Errorf("expected date in YYYY-MM-DD format, got %q", result)
|
|
}
|
|
}
|