33 lines
1.7 KiB
JavaScript
33 lines
1.7 KiB
JavaScript
import { describe, it, expect } from 'vitest'
|
|
import { mapCurrentShoppingList, mapPurchasedShoppingList } from '@/api/mappers/shoppingListMapper'
|
|
|
|
describe('shoppingListMapper', () => {
|
|
it('maps current shopping list and wires references', () => {
|
|
const dto = {
|
|
ingredients_lookup: { 10: { id: 10, name: 'Eggs' } },
|
|
meals_lookup: { 1: { id: 1, suggested_date: '2025-01-01T00:00:00Z', recipes: [], extra_ingredients: [], chefs: [], consumers: [], cleanup: [] } },
|
|
recipes_lookup: { 5: { id: 5, name: 'Omelette' } },
|
|
shopping_list_lookup: { 7: { id: 7, created_date: '2025-01-01T00:00:00Z' } },
|
|
outstanding_items: [{ ingredient_id: 10, meal_id: 1, recipe_id: 5, list_id: 7, created_date: '2025-01-01T00:00:00Z' }],
|
|
requested_meals: [],
|
|
purchased_items: [],
|
|
}
|
|
const mapped = mapCurrentShoppingList(dto)
|
|
const item = mapped.outstanding_items[0]
|
|
expect(item.ingredient.name).toBe('Eggs')
|
|
expect(item.meal.suggested_date).toBeInstanceOf(Date)
|
|
expect(mapped.shopping_list_lookup['7'].created_date).toBeInstanceOf(Date)
|
|
})
|
|
|
|
it('maps purchased shopping list with list dates and item refs', () => {
|
|
const dto = {
|
|
ingredients_lookup: { 10: { id: 10, name: 'Eggs' } },
|
|
meals_lookup: { 1: { id: 1, suggested_date: '2025-01-01T00:00:00Z', recipes: [], extra_ingredients: [], chefs: [], consumers: [], cleanup: [] } },
|
|
recipes_lookup: { 5: { id: 5, name: 'Omelette' } },
|
|
list: { id: 9, created_date: '2025-02-02T00:00:00Z', items: [{ ingredient_id: 10, meal_id: 1, recipe_id: 5, list_id: 9 }] },
|
|
}
|
|
const mapped = mapPurchasedShoppingList(dto)
|
|
expect(mapped.list.created_date).toBeInstanceOf(Date)
|
|
expect(mapped.list.items[0].recipe.name).toBe('Omelette')
|
|
})
|
|
})
|