import { describe, it, expect } from 'vitest' import { server, http, HttpResponse } from './test-setup' import { parseIngredients, parseProduct, parseRecipe } from '@/api/sdk' // Parse endpoints: ingredients, product, recipe describe('parse api (typed client)', () => { it('parses ingredient lines', async () => { server.use( http.get('*/api/v1/recipes/ingredients/parse', () => { return HttpResponse.json([ { id: 1, name: 'Eggs', line: '2 eggs', unit: 'Items', quantity: 2 }, ]) }) ) const result = await parseIngredients(['2 eggs']) expect(result[0].name).toBe('Eggs') }) it('parses a recipe from URL', async () => { server.use( http.get('*/api/v1/recipes/parse', () => { return HttpResponse.json({ id: 10, name: 'Pancakes', ingredients: [] }) }) ) const recipe = await parseRecipe('https://example.com/pancakes') expect(recipe?.name).toBe('Pancakes') }) it('parses/creates a product from URL', async () => { server.use( http.post('*/api/v1/products', async ({ request }) => { const body = await request.json() if (!body?.url) return new HttpResponse(null, { status: 422 }) return HttpResponse.json({ id: 99, name: 'Sample Product', link: body.url, unit: 'Items', imgSmall: '', imgLarge: '', }) }) ) const product = await parseProduct({ name: 'Eggs', line: '2 eggs' }, 'https://store/item') expect(product?.name).toBe('Sample Product') }) })