import { describe, it, expect } from 'vitest' import { mapCurrentShoppingList, mapPurchasedShoppingList } from '@/api/sdk' describe('shoppingListMapper', () => { it('maps current shopping list and wires references', () => { const dto = { ingredientsLookup: { 10: { id: 10, name: 'Eggs' } }, mealsLookup: { 1: { id: 1, suggestedDate: '2025-01-01T00:00:00Z', recipes: [], extraIngredients: [], chefs: [], consumers: [], cleanup: [] } }, recipesLookup: { 5: { id: 5, name: 'Omelette' } }, shoppingListLookup: { 7: { id: 7, createdDate: '2025-01-01T00:00:00Z' } }, outstandingItems: [{ ingredientId: 10, mealId: 1, recipeId: 5, listId: 7, createdDate: '2025-01-01T00:00:00Z' }], requestedMeals: [], purchasedItems: [], } const mapped = mapCurrentShoppingList(dto) // DEBUG // eslint-disable-next-line no-console console.log('mapped current keys:', Object.keys(mapped || {})) const item = mapped.outstandingItems[0] expect(item.ingredient.name).toBe('Eggs') expect(item.meal.suggestedDate).toBeInstanceOf(Date) expect(mapped.shoppingListLookup['7'].createdDate).toBeInstanceOf(Date) }) it('maps purchased shopping list with list dates and item refs', () => { const dto = { ingredientsLookup: { 10: { id: 10, name: 'Eggs' } }, mealsLookup: { 1: { id: 1, suggestedDate: '2025-01-01T00:00:00Z', recipes: [], extraIngredients: [], chefs: [], consumers: [], cleanup: [] } }, recipesLookup: { 5: { id: 5, name: 'Omelette' } }, list: { id: 9, createdDate: '2025-02-02T00:00:00Z', items: [{ ingredientId: 10, mealId: 1, recipeId: 5, listId: 9 }] }, } const mapped = mapPurchasedShoppingList(dto) // DEBUG // eslint-disable-next-line no-console console.log('mapped purchased keys:', Object.keys(mapped || {})) expect(mapped.list.createdDate).toBeInstanceOf(Date) expect(mapped.list.items[0].recipe.name).toBe('Omelette') }) })