diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-07-15 09:41:03 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-07-16 02:50:42 +0000 |
| commit | 7d59a3020c9a98bb8af7240f584ac4c7813a46f6 (patch) | |
| tree | b73648ff848593e4e1ddd017e50471478bee9966 /internal/store/sqlite_test.go | |
| parent | ce1aa62b4b5a3a9af9933e73e416d7ae80142660 (diff) | |
refactor(store): extract meal methods from sqlite.go into meals.go
Pure move: SaveMeals/GetMeals/GetMealsByDateRange and their test
(plus its setupTestStoreWithMeals helper, used only by that test) out
of the 1400+ line sqlite.go into their own file. No behavior change.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VTUSAEKfsPc6WGDq45yPHD
Diffstat (limited to 'internal/store/sqlite_test.go')
| -rw-r--r-- | internal/store/sqlite_test.go | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/internal/store/sqlite_test.go b/internal/store/sqlite_test.go index e8af436..55e1510 100644 --- a/internal/store/sqlite_test.go +++ b/internal/store/sqlite_test.go @@ -340,39 +340,6 @@ func TestGetGoogleTasksByDateRange_IncludesOverdue(t *testing.T) { } } -// setupTestStoreWithMeals creates a test store with meals table -func setupTestStoreWithMeals(t *testing.T) *Store { - t.Helper() - - tempDir := t.TempDir() - dbPath := filepath.Join(tempDir, "test.db") - - db, err := sql.Open("sqlite3", dbPath) - if err != nil { - t.Fatalf("Failed to open test database: %v", err) - } - - db.SetMaxOpenConns(1) - - store := &Store{db: db} - - schema := ` - CREATE TABLE IF NOT EXISTS meals ( - id TEXT PRIMARY KEY, - recipe_name TEXT NOT NULL, - date DATETIME, - meal_type TEXT, - recipe_url TEXT, - updated_at DATETIME DEFAULT CURRENT_TIMESTAMP - ); - ` - if _, err := db.Exec(schema); err != nil { - t.Fatalf("Failed to create schema: %v", err) - } - - return store -} - // TestDeleteCard verifies that DeleteCard removes a card from the cache func TestDeleteCard(t *testing.T) { store := setupTestStoreWithCards(t) @@ -615,38 +582,6 @@ func TestSaveAndGetBoards_ManyBoards(t *testing.T) { } } -func TestGetMealsByDateRange(t *testing.T) { - store := setupTestStoreWithMeals(t) - defer func() { _ = store.Close() }() - - now := time.Now() - tomorrow := now.Add(24 * time.Hour) - - meals := []models.Meal{ - {ID: "1", RecipeName: "Meal 1", Date: now, MealType: "lunch"}, - {ID: "2", RecipeName: "Meal 2", Date: tomorrow, MealType: "dinner"}, - } - - if err := store.SaveMeals(meals); err != nil { - t.Fatalf("Failed to save meals: %v", err) - } - - start := now.Add(-1 * time.Hour) - end := now.Add(1 * time.Hour) - - results, err := store.GetMealsByDateRange(start, end) - if err != nil { - t.Fatalf("GetMealsByDateRange failed: %v", err) - } - - if len(results) != 1 { - t.Errorf("Expected 1 meal, got %d", len(results)) - } - if results[0].ID != "1" { - t.Errorf("Expected meal 1, got %s", results[0].ID) - } -} - func TestGetCardsByDateRange(t *testing.T) { store := setupTestStoreWithCards(t) defer func() { _ = store.Close() }() |
