diff --git a/README.md b/README.md index 6108352..ecb7d94 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Recipe Platform er en responsiv oppskriftsapplikasjon hvor brukere kan utforske - Søk i tittel/beskrivelse, kategori- og tidsfilter samt paginering utføres i backend. Resultatene sorteres med nyeste først. - Bildeopplasting støtter JPG, PNG og WebP, med tilgangskontroll og opprydding. -Applikasjonen bruker ikke lenger prototypeoppskriftene som datakilde. Testene bruker egne fixtures. Valgfri seed oppretter to demooppskrifter; et større eksternt datasett er ikke importert. Se [kjente begrensninger](#kjente-begrensninger). +Applikasjonen bruker ikke lenger prototypeoppskriftene som datakilde. Testene bruker egne fixtures. Valgfri seed oppretter 51 demooppskrifter inkludert bilder; et større eksternt datasett er ikke importert. Se [kjente begrensninger](#kjente-begrensninger). ## Lenker @@ -378,7 +378,7 @@ KI-verktøy får ikke ekte passord, tokens, personopplysninger eller andre hemme - Søk dekker tittel og beskrivelse; ingrediens- og tagsøk er videre arbeid. - Bare nyeste-først-sortering er implementert. Trending og øvrige sorteringer er ikke tilgjengelige. - Utkast beholdes bare i skjemaet og overlever ikke navigering eller oppdatering. -- Seed inneholder to demooppskrifter og demonstrerer ikke ytelse med store datamengder. +- Seed inneholder 51 demooppskrifter og demonstrerer ikke ytelse med store datamengder. - Bildeoperasjoner bruker en global lås for korrekt koordinering. Dette begrenser samtidige skriveoperasjoner. - Bildekvoter har faste grenser. Registrering har IP-begrensning, men flere kontoer kan fortsatt omgå brukerkvotene. Refererte bilder teller mot totalgrensen og slettes ikke av cleanup. - VM-en bruker foreløpig HTTP. HTTPS er nødvendig for å beskytte innlogging under transport. diff --git a/apps/api/src/db/seed-images/american-pancakes.webp b/apps/api/src/db/seed-images/american-pancakes.webp new file mode 100644 index 0000000..b39037b Binary files /dev/null and b/apps/api/src/db/seed-images/american-pancakes.webp differ diff --git a/apps/api/src/db/seed-images/baguette.webp b/apps/api/src/db/seed-images/baguette.webp new file mode 100644 index 0000000..0eaed71 Binary files /dev/null and b/apps/api/src/db/seed-images/baguette.webp differ diff --git a/apps/api/src/db/seed-images/baked-potatoes.webp b/apps/api/src/db/seed-images/baked-potatoes.webp new file mode 100644 index 0000000..32f1252 Binary files /dev/null and b/apps/api/src/db/seed-images/baked-potatoes.webp differ diff --git a/apps/api/src/db/seed-images/beef-burger.webp b/apps/api/src/db/seed-images/beef-burger.webp new file mode 100644 index 0000000..dbb61f9 Binary files /dev/null and b/apps/api/src/db/seed-images/beef-burger.webp differ diff --git a/apps/api/src/db/seed-images/beef-dinner.webp b/apps/api/src/db/seed-images/beef-dinner.webp new file mode 100644 index 0000000..c853c8a Binary files /dev/null and b/apps/api/src/db/seed-images/beef-dinner.webp differ diff --git a/apps/api/src/db/seed-images/bringeb-r-muffins.webp b/apps/api/src/db/seed-images/bringeb-r-muffins.webp new file mode 100644 index 0000000..4f276ac Binary files /dev/null and b/apps/api/src/db/seed-images/bringeb-r-muffins.webp differ diff --git a/apps/api/src/db/seed-images/broth-soup.webp b/apps/api/src/db/seed-images/broth-soup.webp new file mode 100644 index 0000000..878eb80 Binary files /dev/null and b/apps/api/src/db/seed-images/broth-soup.webp differ diff --git a/apps/api/src/db/seed-images/cake.webp b/apps/api/src/db/seed-images/cake.webp new file mode 100644 index 0000000..d326b28 Binary files /dev/null and b/apps/api/src/db/seed-images/cake.webp differ diff --git a/apps/api/src/db/seed-images/car-cake.webp b/apps/api/src/db/seed-images/car-cake.webp new file mode 100644 index 0000000..3937adb Binary files /dev/null and b/apps/api/src/db/seed-images/car-cake.webp differ diff --git a/apps/api/src/db/seed-images/car-muffin.webp b/apps/api/src/db/seed-images/car-muffin.webp new file mode 100644 index 0000000..15a6bb9 Binary files /dev/null and b/apps/api/src/db/seed-images/car-muffin.webp differ diff --git a/apps/api/src/db/seed-images/car-wheels-cake.webp b/apps/api/src/db/seed-images/car-wheels-cake.webp new file mode 100644 index 0000000..14524bd Binary files /dev/null and b/apps/api/src/db/seed-images/car-wheels-cake.webp differ diff --git a/apps/api/src/db/seed-images/carrot-cake.webp b/apps/api/src/db/seed-images/carrot-cake.webp new file mode 100644 index 0000000..39e6e22 Binary files /dev/null and b/apps/api/src/db/seed-images/carrot-cake.webp differ diff --git a/apps/api/src/db/seed-images/chips.webp b/apps/api/src/db/seed-images/chips.webp new file mode 100644 index 0000000..56b080e Binary files /dev/null and b/apps/api/src/db/seed-images/chips.webp differ diff --git a/apps/api/src/db/seed-images/chocolate-cookies.webp b/apps/api/src/db/seed-images/chocolate-cookies.webp new file mode 100644 index 0000000..92d87eb Binary files /dev/null and b/apps/api/src/db/seed-images/chocolate-cookies.webp differ diff --git a/apps/api/src/db/seed-images/chocolate-muffin.webp b/apps/api/src/db/seed-images/chocolate-muffin.webp new file mode 100644 index 0000000..6ea6c7e Binary files /dev/null and b/apps/api/src/db/seed-images/chocolate-muffin.webp differ diff --git a/apps/api/src/db/seed-images/cod.webp b/apps/api/src/db/seed-images/cod.webp new file mode 100644 index 0000000..8b6abbe Binary files /dev/null and b/apps/api/src/db/seed-images/cod.webp differ diff --git a/apps/api/src/db/seed-images/colored-cupcakes.webp b/apps/api/src/db/seed-images/colored-cupcakes.webp new file mode 100644 index 0000000..b4de282 Binary files /dev/null and b/apps/api/src/db/seed-images/colored-cupcakes.webp differ diff --git a/apps/api/src/db/seed-images/english-breakfast.webp b/apps/api/src/db/seed-images/english-breakfast.webp new file mode 100644 index 0000000..b64f7a3 Binary files /dev/null and b/apps/api/src/db/seed-images/english-breakfast.webp differ diff --git a/apps/api/src/db/seed-images/fish-burger.webp b/apps/api/src/db/seed-images/fish-burger.webp new file mode 100644 index 0000000..1e99848 Binary files /dev/null and b/apps/api/src/db/seed-images/fish-burger.webp differ diff --git a/apps/api/src/db/seed-images/fish-n-chips.webp b/apps/api/src/db/seed-images/fish-n-chips.webp new file mode 100644 index 0000000..ea423c4 Binary files /dev/null and b/apps/api/src/db/seed-images/fish-n-chips.webp differ diff --git a/apps/api/src/db/seed-images/fried-chicken.webp b/apps/api/src/db/seed-images/fried-chicken.webp new file mode 100644 index 0000000..18e7868 Binary files /dev/null and b/apps/api/src/db/seed-images/fried-chicken.webp differ diff --git a/apps/api/src/db/seed-images/fried-egg.webp b/apps/api/src/db/seed-images/fried-egg.webp new file mode 100644 index 0000000..ac33b34 Binary files /dev/null and b/apps/api/src/db/seed-images/fried-egg.webp differ diff --git a/apps/api/src/db/seed-images/fried-sausages.webp b/apps/api/src/db/seed-images/fried-sausages.webp new file mode 100644 index 0000000..dbcc384 Binary files /dev/null and b/apps/api/src/db/seed-images/fried-sausages.webp differ diff --git a/apps/api/src/db/seed-images/gingerbread-cookies.webp b/apps/api/src/db/seed-images/gingerbread-cookies.webp new file mode 100644 index 0000000..d8c8c29 Binary files /dev/null and b/apps/api/src/db/seed-images/gingerbread-cookies.webp differ diff --git a/apps/api/src/db/seed-images/grilled-cheese.webp b/apps/api/src/db/seed-images/grilled-cheese.webp new file mode 100644 index 0000000..0aa6920 Binary files /dev/null and b/apps/api/src/db/seed-images/grilled-cheese.webp differ diff --git a/apps/api/src/db/seed-images/homemade-fries.webp b/apps/api/src/db/seed-images/homemade-fries.webp new file mode 100644 index 0000000..a3c7092 Binary files /dev/null and b/apps/api/src/db/seed-images/homemade-fries.webp differ diff --git a/apps/api/src/db/seed-images/indian-dish-with-rice.webp b/apps/api/src/db/seed-images/indian-dish-with-rice.webp new file mode 100644 index 0000000..db30b9d Binary files /dev/null and b/apps/api/src/db/seed-images/indian-dish-with-rice.webp differ diff --git a/apps/api/src/db/seed-images/lasagna.webp b/apps/api/src/db/seed-images/lasagna.webp new file mode 100644 index 0000000..d0c596c Binary files /dev/null and b/apps/api/src/db/seed-images/lasagna.webp differ diff --git a/apps/api/src/db/seed-images/masala.webp b/apps/api/src/db/seed-images/masala.webp new file mode 100644 index 0000000..20f02e8 Binary files /dev/null and b/apps/api/src/db/seed-images/masala.webp differ diff --git a/apps/api/src/db/seed-images/norsk-matpakke.webp b/apps/api/src/db/seed-images/norsk-matpakke.webp new file mode 100644 index 0000000..5181b65 Binary files /dev/null and b/apps/api/src/db/seed-images/norsk-matpakke.webp differ diff --git a/apps/api/src/db/seed-images/oatmeal-muffin.webp b/apps/api/src/db/seed-images/oatmeal-muffin.webp new file mode 100644 index 0000000..8593b33 Binary files /dev/null and b/apps/api/src/db/seed-images/oatmeal-muffin.webp differ diff --git a/apps/api/src/db/seed-images/orange-cake.webp b/apps/api/src/db/seed-images/orange-cake.webp new file mode 100644 index 0000000..2f54379 Binary files /dev/null and b/apps/api/src/db/seed-images/orange-cake.webp differ diff --git a/apps/api/src/db/seed-images/pancakes.webp b/apps/api/src/db/seed-images/pancakes.webp new file mode 100644 index 0000000..098b184 Binary files /dev/null and b/apps/api/src/db/seed-images/pancakes.webp differ diff --git a/apps/api/src/db/seed-images/peanut-soup.webp b/apps/api/src/db/seed-images/peanut-soup.webp new file mode 100644 index 0000000..79ec72b Binary files /dev/null and b/apps/api/src/db/seed-images/peanut-soup.webp differ diff --git a/apps/api/src/db/seed-images/peppered-eggs.webp b/apps/api/src/db/seed-images/peppered-eggs.webp new file mode 100644 index 0000000..5b2ee81 Binary files /dev/null and b/apps/api/src/db/seed-images/peppered-eggs.webp differ diff --git a/apps/api/src/db/seed-images/plain-rice.webp b/apps/api/src/db/seed-images/plain-rice.webp new file mode 100644 index 0000000..6f3a9c9 Binary files /dev/null and b/apps/api/src/db/seed-images/plain-rice.webp differ diff --git a/apps/api/src/db/seed-images/potato-boats.webp b/apps/api/src/db/seed-images/potato-boats.webp new file mode 100644 index 0000000..8e303e2 Binary files /dev/null and b/apps/api/src/db/seed-images/potato-boats.webp differ diff --git a/apps/api/src/db/seed-images/raw-egg.webp b/apps/api/src/db/seed-images/raw-egg.webp new file mode 100644 index 0000000..bec966b Binary files /dev/null and b/apps/api/src/db/seed-images/raw-egg.webp differ diff --git a/apps/api/src/db/seed-images/roasted-chicken.webp b/apps/api/src/db/seed-images/roasted-chicken.webp new file mode 100644 index 0000000..84011b8 Binary files /dev/null and b/apps/api/src/db/seed-images/roasted-chicken.webp differ diff --git a/apps/api/src/db/seed-images/roasted-coffee-beans.webp b/apps/api/src/db/seed-images/roasted-coffee-beans.webp new file mode 100644 index 0000000..f9f9f6e Binary files /dev/null and b/apps/api/src/db/seed-images/roasted-coffee-beans.webp differ diff --git a/apps/api/src/db/seed-images/salmon.webp b/apps/api/src/db/seed-images/salmon.webp new file mode 100644 index 0000000..fa00d5e Binary files /dev/null and b/apps/api/src/db/seed-images/salmon.webp differ diff --git a/apps/api/src/db/seed-images/sausage.webp b/apps/api/src/db/seed-images/sausage.webp new file mode 100644 index 0000000..cb6129c Binary files /dev/null and b/apps/api/src/db/seed-images/sausage.webp differ diff --git a/apps/api/src/db/seed-images/shells.webp b/apps/api/src/db/seed-images/shells.webp new file mode 100644 index 0000000..200bac1 Binary files /dev/null and b/apps/api/src/db/seed-images/shells.webp differ diff --git a/apps/api/src/db/seed-images/shrimp-salad.webp b/apps/api/src/db/seed-images/shrimp-salad.webp new file mode 100644 index 0000000..dd60325 Binary files /dev/null and b/apps/api/src/db/seed-images/shrimp-salad.webp differ diff --git a/apps/api/src/db/seed-images/slovenian-pancakes.webp b/apps/api/src/db/seed-images/slovenian-pancakes.webp new file mode 100644 index 0000000..eb27ff3 Binary files /dev/null and b/apps/api/src/db/seed-images/slovenian-pancakes.webp differ diff --git a/apps/api/src/db/seed-images/sweet-potato-soup.webp b/apps/api/src/db/seed-images/sweet-potato-soup.webp new file mode 100644 index 0000000..4d79e3a Binary files /dev/null and b/apps/api/src/db/seed-images/sweet-potato-soup.webp differ diff --git a/apps/api/src/db/seed-images/tiki-masala.webp b/apps/api/src/db/seed-images/tiki-masala.webp new file mode 100644 index 0000000..7b443b8 Binary files /dev/null and b/apps/api/src/db/seed-images/tiki-masala.webp differ diff --git a/apps/api/src/db/seed-images/tomato-soup.webp b/apps/api/src/db/seed-images/tomato-soup.webp new file mode 100644 index 0000000..0c16f3b Binary files /dev/null and b/apps/api/src/db/seed-images/tomato-soup.webp differ diff --git a/apps/api/src/db/seed-images/vanilla-cake.webp b/apps/api/src/db/seed-images/vanilla-cake.webp new file mode 100644 index 0000000..bfaa828 Binary files /dev/null and b/apps/api/src/db/seed-images/vanilla-cake.webp differ diff --git a/apps/api/src/db/seed-images/white-cookies.webp b/apps/api/src/db/seed-images/white-cookies.webp new file mode 100644 index 0000000..dcdddb5 Binary files /dev/null and b/apps/api/src/db/seed-images/white-cookies.webp differ diff --git a/apps/api/src/db/seed-images/yellow-rice-with-chikcen.webp b/apps/api/src/db/seed-images/yellow-rice-with-chikcen.webp new file mode 100644 index 0000000..ddf4d22 Binary files /dev/null and b/apps/api/src/db/seed-images/yellow-rice-with-chikcen.webp differ diff --git a/apps/api/src/db/seedData.ts b/apps/api/src/db/seedData.ts index 42554bd..3bf04a6 100644 --- a/apps/api/src/db/seedData.ts +++ b/apps/api/src/db/seedData.ts @@ -1,57 +1,231 @@ +// Explicit opt-in demo data; never run automatically during deploy. + import { hash } from 'argon2'; +import { createHash } from 'node:crypto'; +import { copyFile, mkdir, readFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { Pool } from 'pg'; -// Explicit opt-in demo data; never run automatically during deploy. -const authorId = '11111111-1111-4111-8111-111111111111'; +import { seedRecipes } from './seedRecipes.js'; + +const AUTHOR_ID = '11111111-1111-4111-8111-111111111111'; + +const IMAGE_SOURCE_DIR = fileURLToPath( + new URL('./seed-images/', import.meta.url), +); + +const DEFAULT_UPLOAD_DIR = fileURLToPath( + new URL('../../../../uploads/', import.meta.url), +); + +const MAX_IMAGE_BYTES = 10 * 1024 * 1024; + +function stableUuid(value: string): string { + const hex = createHash('sha256').update(`t31-demo-v1:${value}`).digest('hex'); + + return [ + hex.slice(0, 8), + hex.slice(8, 12), + `4${hex.slice(13, 16)}`, + `a${hex.slice(17, 20)}`, + hex.slice(20, 32), + ].join('-'); +} + +function imageFilename(slug: string): string { + const safeName = slug + .trim() + .toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/^-|-$/g, ''); + + return `${safeName}.webp`; +} + export async function seedDatabase( pool: Pool, password: string | undefined, schema = 'project2', + uploadDir = process.env.UPLOAD_DIR ?? DEFAULT_UPLOAD_DIR, ) { - if (!/^[a-z_][a-z0-9_]*$/.test(schema)) + if (!/^[a-z_][a-z0-9_]*$/.test(schema)) { throw new Error('Invalid database schema.'); + } + if (!password || password.length < 12) { - throw new Error( - 'Set SEED_PASSWORD (at least 12 characters) before running db:seed.', - ); + throw new Error('Set SEED_PASSWORD to at least 12 characters.'); } + const prepared = await Promise.all( + seedRecipes.map(async (recipe) => { + const sourcePath = join(IMAGE_SOURCE_DIR, imageFilename(recipe.slug)); + + const image = await readFile(sourcePath).catch(() => { + throw new Error(`Missing image: ${sourcePath}`); + }); + + if (image.length === 0 || image.length > MAX_IMAGE_BYTES) { + throw new Error(`Invalid image size: ${sourcePath}`); + } + + if ( + image.toString('ascii', 0, 4) !== 'RIFF' || + image.toString('ascii', 8, 12) !== 'WEBP' + ) { + throw new Error(`Expected a WebP image: ${sourcePath}`); + } + + const filename = `${stableUuid(`image:${recipe.slug}`)}.webp`; + + return { + recipe, + recipeId: stableUuid(`recipe:${recipe.slug}`), + sourcePath, + filename, + imageUrl: `/uploads/${filename}`, + byteSize: image.length, + }; + }), + ); + + await mkdir(uploadDir, { recursive: true }); + const passwordHash = await hash(password); const client = await pool.connect(); + try { await client.query('BEGIN'); + await client.query( - `INSERT INTO ${schema}.users (id,name,email,password_hash) - VALUES ($1,'Demo Cook','demo@example.invalid',$2) ON CONFLICT (id) DO NOTHING`, - [authorId, passwordHash], + `INSERT INTO ${schema}.users + (id, name, email, password_hash) + VALUES ($1, $2, $3, $4) + ON CONFLICT (id) DO NOTHING`, + [AUTHOR_ID, 'Demo Cook', 'demo@example.invalid', passwordHash], ); - for (const [id, title, visibility] of [ - ['22222222-2222-4222-8222-222222222222', 'Demo vegetable soup', 'public'], - ['33333333-3333-4333-8333-333333333333', 'Demo private soup', 'private'], - ]) { - const inserted = await client.query( - `INSERT INTO ${schema}.recipes - (id,author_id,title,description,category,difficulty,visibility,prep_minutes,cook_minutes,servings) - VALUES ($1,$2,$3,'Simple demonstration recipe','soup','easy',$4,5,15,2) - ON CONFLICT (id) DO NOTHING RETURNING id`, - [id, authorId, title, visibility], + + for (const item of prepared) { + const { recipe } = item; + + const destination = join(uploadDir, item.filename); + + await copyFile(item.sourcePath, destination); + + await client.query( + `INSERT INTO ${schema}.uploaded_images + (filename, owner_id, byte_size) + VALUES ($1, $2, $3) + ON CONFLICT (filename) + DO UPDATE SET + byte_size = EXCLUDED.byte_size`, + [item.filename, AUTHOR_ID, item.byteSize], ); - if (!inserted.rowCount) continue; + await client.query( - `INSERT INTO ${schema}.recipe_ingredients (recipe_id,name,amount,unit,position) - VALUES ($1,'Water',500,'ml',1),($1,'Carrots',2,'',2)`, - [id], + `INSERT INTO ${schema}.recipes ( + id, + author_id, + title, + description, + image_url, + category, + cuisine, + difficulty, + visibility, + prep_minutes, + cook_minutes, + servings + ) + VALUES ( + $1, $2, $3, $4, $5, $6, + $7, $8, $9, $10, $11, $12 + ) + ON CONFLICT (id) + DO UPDATE SET + title = EXCLUDED.title, + description = EXCLUDED.description, + image_url = EXCLUDED.image_url, + category = EXCLUDED.category, + cuisine = EXCLUDED.cuisine, + difficulty = EXCLUDED.difficulty, + visibility = EXCLUDED.visibility, + prep_minutes = EXCLUDED.prep_minutes, + cook_minutes = EXCLUDED.cook_minutes, + servings = EXCLUDED.servings, + updated_at = now()`, + [ + item.recipeId, + AUTHOR_ID, + recipe.title, + recipe.description, + item.imageUrl, + recipe.category, + recipe.cuisine, + recipe.difficulty, + recipe.visibility, + recipe.prepMinutes, + recipe.cookMinutes, + recipe.servings, + ], ); + await client.query( - `INSERT INTO ${schema}.recipe_instructions (recipe_id,text,position) - VALUES ($1,'Chop the carrots.',1),($1,'Simmer in water until tender.',2)`, - [id], + `DELETE FROM ${schema}.recipe_ingredients + WHERE recipe_id = $1`, + [item.recipeId], ); + await client.query( - `INSERT INTO ${schema}.recipe_tags (recipe_id,tag) VALUES ($1,'demo')`, - [id], + `DELETE FROM ${schema}.recipe_instructions + WHERE recipe_id = $1`, + [item.recipeId], ); + + await client.query( + `DELETE FROM ${schema}.recipe_tags + WHERE recipe_id = $1`, + [item.recipeId], + ); + + for (const [index, ingredient] of recipe.ingredients.entries()) { + await client.query( + `INSERT INTO ${schema}.recipe_ingredients + (recipe_id, name, amount, unit, position) + VALUES ($1, $2, $3, $4, $5)`, + [ + item.recipeId, + ingredient.name, + ingredient.amount, + ingredient.unit, + index + 1, + ], + ); + } + + for (const [index, instruction] of recipe.instructions.entries()) { + await client.query( + `INSERT INTO ${schema}.recipe_instructions + (recipe_id, text, position) + VALUES ($1, $2, $3)`, + [item.recipeId, instruction, index + 1], + ); + } + + for (const tag of new Set(recipe.tags)) { + await client.query( + `INSERT INTO ${schema}.recipe_tags + (recipe_id, tag) + VALUES ($1, $2)`, + [item.recipeId, tag], + ); + } + + console.log(`Seeded: ${recipe.title}`); } + await client.query('COMMIT'); + + console.log(`Successfully seeded ${prepared.length} recipes.`); } catch (error) { await client.query('ROLLBACK'); throw error; diff --git a/apps/api/src/db/seedRecipes.ts b/apps/api/src/db/seedRecipes.ts new file mode 100644 index 0000000..5061940 --- /dev/null +++ b/apps/api/src/db/seedRecipes.ts @@ -0,0 +1,660 @@ +export type DemoRecipe = { + slug: string; + title: string; + description: string; + category: 'breakfast' | 'lunch' | 'dinner' | 'dessert' | 'soup'; + cuisine: string; + difficulty: 'easy' | 'medium' | 'hard'; + visibility: 'public' | 'private'; + prepMinutes: number; + cookMinutes: number; + servings: number; + ingredients: { + name: string; + amount: number; + unit: string; + }[]; + instructions: string[]; + tags: string[]; +}; + +type Category = DemoRecipe['category']; + +// Each recipe contains: +// title, category, cuisine, prep minutes, cook minutes, +// ingredients, instructions +type RawRecipe = [string, Category, string, number, number, string, string]; + +// Ingredients: name:quantity:unit, separated by | +// Instructions: steps separated by | + +const recipes: Record = { + // ================================================== + // DINNER AND SAVORY DISHES + // ================================================== + + lasagna: [ + 'Classic Homemade Lasagna', + 'dinner', + 'Italian', + 30, + 45, + 'Lasagna sheets:12:pcs|Ground beef:500:g|Chopped tomatoes:400:g|Tomato paste:2:tbsp|Onion:1:pcs|Garlic:2:cloves|Mozzarella:200:g|Béchamel sauce:400:ml|Olive oil:2:tbsp', + 'Preheat oven to 190°C.|Chop onion and garlic and soften in olive oil.|Brown the ground beef.|Add tomatoes and tomato paste and simmer for 15 minutes.|Layer meat sauce, lasagna sheets and béchamel in a baking dish.|Finish with mozzarella.|Bake for 35–45 minutes until golden and cooked through.|Rest for 10 minutes before serving.', + ], + + 'fish-burger': [ + 'Crispy Fish Burger', + 'lunch', + 'International', + 20, + 15, + 'White fish fillets:500:g|Burger buns:4:pcs|Breadcrumbs:120:g|Eggs:2:pcs|Lettuce:4:leaves|Mayonnaise:80:g|Lemon:1:pcs', + 'Pat fish dry and cut into burger-sized pieces.|Dip fish into beaten egg and then breadcrumbs.|Pan-fry until golden and cooked through.|Toast burger buns.|Mix mayonnaise with lemon juice.|Assemble burgers with lettuce, fish and lemon mayonnaise.', + ], + + 'beef-burger': [ + 'Classic Beef Cheeseburger', + 'dinner', + 'American', + 15, + 15, + 'Ground beef:600:g|Burger buns:4:pcs|Cheddar cheese:4:slices|Lettuce:4:leaves|Tomatoes:2:pcs|Red onion:1:pcs|Burger sauce:80:g', + 'Divide ground beef into four patties.|Season with salt and pepper.|Cook in a hot skillet until fully cooked.|Add cheddar during the final minute.|Toast burger buns.|Assemble with lettuce, tomato, onion and burger sauce.', + ], + + 'potato-boats': [ + 'Cheesy Loaded Potato Boats', + 'dinner', + 'American', + 20, + 55, + 'Large potatoes:4:pcs|Cheddar cheese:150:g|Sour cream:120:g|Butter:40:g|Spring onions:3:pcs|Paprika:1:tsp', + 'Bake whole potatoes at 200°C until tender.|Cut each potato in half.|Scoop out some potato flesh while leaving the skin intact.|Mash the flesh with butter and cheese.|Return filling to potato skins.|Bake again until golden.|Serve with sour cream and chopped spring onions.', + ], + + 'baked-potatoes': [ + 'Classic Oven-Baked Potatoes', + 'dinner', + 'International', + 10, + 55, + 'Large potatoes:4:pcs|Olive oil:2:tbsp|Sea salt:1:tsp|Butter:60:g|Sour cream:100:g', + 'Preheat oven to 200°C.|Wash and dry potatoes.|Prick the skins with a fork.|Rub with oil and salt.|Bake directly on a baking tray until tender.|Cut open and serve with butter and sour cream.', + ], + + shells: [ + 'Creamy Garlic Pasta Shells', + 'dinner', + 'Italian', + 10, + 20, + 'Pasta shells:400:g|Cooking cream:250:ml|Parmesan:90:g|Garlic:3:cloves|Butter:30:g|Parsley:10:g', + 'Cook pasta shells in salted water until al dente.|Reserve a little pasta water.|Melt butter and gently sauté minced garlic.|Add cream and parmesan.|Combine with pasta, loosening with pasta water if needed.|Garnish with parsley.', + ], + + salmon: [ + 'Lemon and Dill Baked Salmon', + 'dinner', + 'Nordic', + 10, + 20, + 'Salmon fillets:600:g|Lemon:1:pcs|Fresh dill:15:g|Olive oil:2:tbsp|Garlic:2:cloves|Salt:1:tsp', + 'Preheat oven to 190°C.|Place salmon in a baking dish.|Mix olive oil, lemon juice, dill and garlic.|Brush the mixture over salmon.|Bake until the salmon is cooked through.|Serve with potatoes or vegetables.', + ], + + cod: [ + 'Butter-Baked Cod with Lemon', + 'dinner', + 'Nordic', + 10, + 18, + 'Cod fillets:600:g|Butter:60:g|Lemon:1:pcs|Fresh parsley:15:g|Garlic:2:cloves|Salt:1:tsp', + 'Preheat oven to 190°C.|Arrange cod in a lightly greased dish.|Melt butter with garlic and lemon juice.|Pour the butter mixture over fish.|Bake until the cod is opaque and flakes easily.|Sprinkle with parsley.', + ], + + 'fried-chicken': [ + 'Southern-Style Crispy Fried Chicken', + 'dinner', + 'American', + 30, + 30, + 'Chicken thighs:800:g|Buttermilk:300:ml|Flour:250:g|Paprika:2:tsp|Garlic powder:2:tsp|Black pepper:1:tsp|Frying oil:600:ml', + 'Marinate chicken in buttermilk in the refrigerator.|Combine flour with spices.|Coat chicken thoroughly in the flour mixture.|Heat oil to approximately 175°C.|Fry in batches without overcrowding.|Check chicken reaches 74°C internally.|Drain briefly before serving.', + ], + + 'beef-dinner': [ + 'Pan-Seared Beef with Potatoes', + 'dinner', + 'European', + 20, + 30, + 'Beef steaks:600:g|Potatoes:600:g|Green beans:250:g|Butter:60:g|Garlic:3:cloves|Olive oil:2:tbsp', + 'Cut potatoes into wedges and roast with olive oil.|Season steaks with salt and pepper.|Sear steaks in a hot pan and cook to your preferred safe doneness.|Add butter and garlic and baste the steaks.|Steam green beans until tender.|Rest steaks before serving.', + ], + + sausage: [ + 'Roasted Sausages with Peppers', + 'dinner', + 'European', + 15, + 30, + 'Sausages:600:g|Bell peppers:3:pcs|Red onion:2:pcs|Olive oil:3:tbsp|Paprika:1:tsp|Garlic:2:cloves', + 'Preheat oven to 200°C.|Slice peppers and onions.|Arrange vegetables and sausages on a baking tray.|Drizzle with olive oil and season.|Roast until the sausages are cooked through and vegetables are soft.|Serve with bread or potatoes.', + ], + + 'fried-sausages': [ + 'Pan-Fried Sausages and Onions', + 'breakfast', + 'European', + 10, + 20, + 'Sausages:400:g|Onions:2:pcs|Butter:20:g|Olive oil:1:tbsp|Black pepper:1:tsp', + 'Slice onions thinly.|Heat butter and oil in a frying pan.|Cook onions until golden and softened.|Add sausages and turn regularly.|Continue until sausages are completely cooked.|Serve immediately.', + ], + + 'fish-n-chips': [ + 'Traditional Fish and Chips', + 'dinner', + 'British', + 30, + 30, + 'Cod fillets:600:g|Potatoes:800:g|Plain flour:180:g|Sparkling water:250:ml|Baking powder:1:tsp|Frying oil:750:ml|Lemon:1:pcs', + 'Cut potatoes into thick chips and dry thoroughly.|Prepare a batter from flour, baking powder and sparkling water.|Fry or oven-bake potato chips until golden.|Coat cod in batter.|Fry fish until crisp and thoroughly cooked.|Drain and serve with lemon.', + ], + + masala: [ + 'Vegetable Masala Curry', + 'dinner', + 'Indian-inspired', + 20, + 30, + 'Chickpeas:400:g|Chopped tomatoes:400:g|Coconut milk:300:ml|Onion:1:pcs|Garlic:3:cloves|Ginger:20:g|Garam masala:2:tsp|Spinach:120:g', + 'Chop onion, garlic and ginger.|Sauté onion until softened.|Add garlic, ginger and garam masala.|Add tomatoes, chickpeas and coconut milk.|Simmer for 20 minutes.|Stir in spinach and cook until wilted.|Serve with rice.', + ], + + 'tiki-masala': [ + 'Creamy Chicken Tikka Masala', + 'dinner', + 'Indian-inspired', + 25, + 35, + 'Chicken breast:650:g|Tomato passata:400:ml|Cooking cream:200:ml|Natural yogurt:120:g|Onion:1:pcs|Garlic:3:cloves|Garam masala:2:tsp|Ginger:20:g', + 'Cut chicken into bite-sized pieces.|Coat chicken with yogurt and some garam masala.|Sauté chopped onion, garlic and ginger.|Add chicken and cook until lightly browned.|Pour in tomato passata and simmer until chicken is fully cooked.|Stir in cream and remaining spices.|Serve with rice or naan.', + ], + + 'roasted-chicken': [ + 'Herb-Roasted Whole Chicken', + 'dinner', + 'European', + 20, + 85, + 'Whole chicken:1500:g|Butter:70:g|Lemon:1:pcs|Garlic:5:cloves|Rosemary:15:g|Thyme:10:g|Potatoes:700:g', + 'Preheat oven to 190°C.|Pat chicken dry.|Rub with softened butter, herbs and garlic.|Place lemon inside the cavity.|Arrange potatoes around the chicken.|Roast until the thickest meat reaches 74°C.|Rest before carving and serving.', + ], + + 'indian-dish-with-rice': [ + 'Spiced Chickpea Curry with Rice', + 'dinner', + 'Indian-inspired', + 15, + 30, + 'Basmati rice:300:g|Chickpeas:400:g|Chopped tomatoes:400:g|Onion:1:pcs|Curry powder:2:tsp|Garlic:2:cloves|Vegetable oil:2:tbsp', + 'Rinse and cook basmati rice.|Finely chop onion and garlic.|Sauté onion in oil and add spices.|Stir in tomatoes and chickpeas.|Simmer until the sauce thickens.|Serve the curry over fluffy rice.', + ], + + 'yellow-rice-with-chikcen': [ + 'Golden Chicken and Turmeric Rice', + 'dinner', + 'International', + 20, + 35, + 'Chicken breast:600:g|Long-grain rice:300:g|Chicken broth:650:ml|Turmeric:2:tsp|Onion:1:pcs|Garlic:2:cloves|Olive oil:2:tbsp', + 'Cut chicken into small pieces.|Sauté chopped onion and garlic.|Add chicken and brown lightly.|Stir in rice and turmeric.|Pour in chicken broth.|Simmer covered until rice is tender and chicken is fully cooked.|Rest covered before fluffing.', + ], + + // ================================================== + // SOUPS + // ================================================== + + 'peanut-soup': [ + 'Creamy Peanut and Sweet Potato Soup', + 'soup', + 'West African-inspired', + 15, + 35, + 'Sweet potatoes:500:g|Peanut butter:150:g|Chopped tomatoes:400:g|Vegetable broth:850:ml|Onion:1:pcs|Garlic:3:cloves|Ginger:15:g', + 'Peel and dice sweet potatoes.|Sauté onion, garlic and ginger.|Add sweet potatoes, tomatoes and broth.|Simmer until the potatoes are tender.|Stir in peanut butter until smooth.|Season and serve warm.', + ], + + 'tomato-soup': [ + 'Creamy Homemade Tomato Soup', + 'soup', + 'International', + 15, + 30, + 'Ripe tomatoes:800:g|Vegetable broth:500:ml|Onion:1:pcs|Garlic:3:cloves|Olive oil:2:tbsp|Cooking cream:100:ml|Basil:10:g', + 'Chop tomatoes, onion and garlic.|Sauté onion and garlic in olive oil.|Add tomatoes and broth.|Simmer for 25 minutes.|Blend until smooth.|Stir in cream and garnish with basil.', + ], + + 'sweet-potato-soup': [ + 'Velvety Sweet Potato Soup', + 'soup', + 'International', + 15, + 30, + 'Sweet potatoes:700:g|Vegetable broth:750:ml|Onion:1:pcs|Garlic:2:cloves|Coconut milk:200:ml|Olive oil:2:tbsp|Paprika:1:tsp', + 'Peel and cube sweet potatoes.|Sauté onion and garlic.|Add sweet potatoes, paprika and broth.|Simmer until tender.|Blend until creamy.|Stir in coconut milk and warm gently.', + ], + + 'broth-soup': [ + 'Comforting Vegetable Noodle Broth', + 'soup', + 'International', + 15, + 25, + 'Vegetable broth:1000:ml|Carrots:2:pcs|Celery:2:stalks|Egg noodles:150:g|Onion:1:pcs|Parsley:10:g', + 'Dice carrots, celery and onion.|Bring broth to a simmer.|Add vegetables and cook until almost tender.|Add noodles and cook according to package instructions.|Season and finish with parsley.', + ], + + // ================================================== + // BREAKFAST + // ================================================== + + pancakes: [ + 'Traditional Norwegian Pancakes', + 'breakfast', + 'Norwegian', + 10, + 25, + 'Plain flour:200:g|Milk:500:ml|Eggs:3:pcs|Butter:40:g|Salt:1:pinch', + 'Whisk eggs and milk together.|Gradually add flour and salt.|Let batter rest for 10 minutes.|Melt a little butter in a frying pan.|Cook thin pancakes until golden on both sides.|Serve with jam or berries.', + ], + + 'american-pancakes': [ + 'Fluffy American Pancakes', + 'breakfast', + 'American', + 10, + 20, + 'Plain flour:250:g|Milk:300:ml|Eggs:2:pcs|Baking powder:2:tsp|Sugar:2:tbsp|Butter:40:g', + 'Mix flour, baking powder and sugar.|Whisk eggs and milk separately.|Combine wet and dry ingredients gently.|Heat a lightly buttered pan.|Cook small thick pancakes until bubbles appear.|Flip and cook until golden.', + ], + + 'slovenian-pancakes': [ + 'Slovenian Palačinke with Jam', + 'breakfast', + 'Slovenian', + 15, + 20, + 'Plain flour:220:g|Milk:450:ml|Eggs:3:pcs|Butter:30:g|Apricot jam:150:g|Icing sugar:20:g', + 'Whisk flour, milk and eggs into a smooth batter.|Rest the mixture briefly.|Cook very thin pancakes in a lightly buttered pan.|Spread each pancake with apricot jam.|Roll up and dust with icing sugar.', + ], + + 'peppered-eggs': [ + 'Creamy Scrambled Eggs with Pepper', + 'breakfast', + 'International', + 5, + 10, + 'Eggs:4:pcs|Butter:25:g|Milk:40:ml|Black pepper:1:tsp|Salt:1:pinch', + 'Crack eggs into a bowl.|Whisk with milk and salt.|Melt butter over low heat.|Add eggs and stir gently until softly set.|Finish with freshly ground black pepper.', + ], + + 'fried-egg': [ + 'Simple Sunny-Side-Up Eggs', + 'breakfast', + 'International', + 5, + 5, + 'Eggs:2:pcs|Butter:20:g|Salt:1:pinch|Black pepper:1:pinch', + 'Heat butter in a nonstick frying pan.|Crack eggs carefully into the pan.|Cook gently until the whites are fully set.|Season with salt and pepper.|Serve with toast.', + ], + + 'english-breakfast': [ + 'Full English Breakfast', + 'breakfast', + 'British', + 15, + 25, + 'Eggs:2:pcs|Breakfast sausages:2:pcs|Baked beans:200:g|Mushrooms:150:g|Tomatoes:2:pcs|Bread:2:slices|Butter:20:g', + 'Cook sausages thoroughly in a frying pan.|Sauté mushrooms and halved tomatoes.|Warm baked beans in a saucepan.|Toast bread and butter lightly.|Fry the eggs.|Arrange everything on a warm plate.', + ], + + 'raw-egg': [ + 'Basic Boiled Eggs', + 'breakfast', + 'International', + 5, + 10, + 'Eggs:2:pcs|Water:700:ml|Salt:1:pinch', + 'Bring water to a gentle boil.|Carefully lower eggs into the water.|Simmer for 8–10 minutes for firm yolks.|Transfer to cold water.|Peel and serve.', + ], + + 'roasted-coffee-beans': [ + 'Freshly Brewed Filter Coffee', + 'breakfast', + 'International', + 5, + 5, + 'Roasted coffee beans:35:g|Water:550:ml', + 'Grind coffee beans to a medium consistency.|Heat water to approximately 92–96°C.|Place grounds in a paper filter.|Pour hot water evenly over the coffee.|Allow the coffee to brew and serve immediately.', + ], + + // ================================================== + // LUNCHES AND LIGHT MEALS + // ================================================== + + 'shrimp-salad': [ + 'Fresh Shrimp and Avocado Salad', + 'lunch', + 'International', + 20, + 0, + 'Cooked shrimp:400:g|Mixed lettuce:150:g|Avocado:2:pcs|Cucumber:1:pcs|Cherry tomatoes:200:g|Lemon:1:pcs|Olive oil:2:tbsp', + 'Wash and dry the salad greens.|Slice avocado and cucumber.|Halve cherry tomatoes.|Arrange vegetables with cooked chilled shrimp.|Whisk lemon juice and olive oil.|Drizzle dressing over the salad before serving.', + ], + + 'homemade-fries': [ + 'Crispy Oven-Baked French Fries', + 'lunch', + 'International', + 20, + 40, + 'Potatoes:800:g|Olive oil:3:tbsp|Paprika:1:tsp|Garlic powder:1:tsp|Salt:1:tsp', + 'Preheat oven to 220°C.|Cut potatoes into even sticks.|Rinse and dry thoroughly.|Toss with oil and spices.|Spread in a single layer on a baking tray.|Bake until crisp, turning halfway through.', + ], + + 'grilled-cheese': [ + 'Golden Grilled Cheese Sandwich', + 'lunch', + 'American', + 5, + 10, + 'Sourdough bread:4:slices|Cheddar cheese:160:g|Butter:40:g|Dijon mustard:2:tsp', + 'Spread butter on the outside of each bread slice.|Add cheddar and a little mustard between the slices.|Heat a frying pan over medium-low heat.|Cook each sandwich until golden on both sides and the cheese has melted.|Slice and serve hot.', + ], + + 'norsk-matpakke': [ + 'Traditional Norwegian Matpakke', + 'lunch', + 'Norwegian', + 15, + 0, + 'Wholegrain bread:4:slices|Brown cheese:40:g|White cheese:60:g|Cucumber:0.5:pcs|Ham:60:g|Butter:20:g', + 'Spread a thin layer of butter on the bread.|Arrange brown cheese on one slice.|Add white cheese and ham to the remaining slices.|Slice cucumber and place over the toppings.|Pack sandwiches using sandwich paper.|Keep perishable toppings cool until lunch.', + ], + + baguette: [ + 'Fresh Ham and Cheese Baguette', + 'lunch', + 'French-inspired', + 10, + 0, + 'Baguette:1:pcs|Ham:120:g|Cheddar cheese:100:g|Lettuce:4:leaves|Tomatoes:2:pcs|Mayonnaise:40:g', + 'Slice the baguette lengthwise.|Spread mayonnaise over the cut sides.|Add lettuce, sliced tomatoes, ham and cheese.|Close the baguette.|Cut into portions and serve.', + ], + + chips: [ + 'Homemade Crispy Potato Chips', + 'lunch', + 'International', + 20, + 25, + 'Potatoes:500:g|Olive oil:2:tbsp|Sea salt:1:tsp|Paprika:1:tsp', + 'Preheat oven to 200°C.|Slice potatoes as thinly and evenly as possible.|Pat slices dry.|Toss with a little oil and seasoning.|Arrange in a single layer.|Bake until golden and crisp, watching closely near the end.', + ], + + 'plain-rice': [ + 'Perfect Fluffy White Rice', + 'lunch', + 'International', + 5, + 20, + 'Long-grain rice:300:g|Water:600:ml|Salt:1:tsp', + 'Rinse rice under cold water.|Add rice, water and salt to a saucepan.|Bring to a boil.|Reduce heat and cover.|Simmer until the water is absorbed.|Rest covered for 5 minutes and fluff with a fork.', + ], + + // ================================================== + // CAKES + // ================================================== + + cake: [ + 'Classic Celebration Cake', + 'dessert', + 'International', + 30, + 35, + 'Plain flour:250:g|Sugar:200:g|Butter:180:g|Eggs:4:pcs|Milk:120:ml|Baking powder:2:tsp|Vanilla extract:2:tsp', + 'Preheat oven to 175°C.|Cream butter and sugar until light.|Beat in eggs one at a time.|Fold in flour and baking powder alternately with milk.|Add vanilla.|Transfer to a greased cake tin.|Bake until golden and a skewer comes out clean.|Cool before decorating.', + ], + + 'carrot-cake': [ + 'Moist Cinnamon Carrot Cake', + 'dessert', + 'International', + 25, + 45, + 'Carrots:350:g|Plain flour:250:g|Brown sugar:180:g|Eggs:3:pcs|Vegetable oil:180:ml|Cinnamon:2:tsp|Baking powder:2:tsp|Cream cheese:200:g|Icing sugar:80:g', + 'Preheat oven to 175°C.|Grate carrots finely.|Whisk eggs, sugar and oil.|Fold in flour, baking powder and cinnamon.|Add grated carrots.|Bake until a skewer comes out clean.|Cool completely.|Beat cream cheese with icing sugar and spread over the cake.', + ], + + 'orange-cake': [ + 'Fresh Orange Sponge Cake', + 'dessert', + 'International', + 20, + 40, + 'Oranges:2:pcs|Plain flour:240:g|Sugar:170:g|Butter:150:g|Eggs:3:pcs|Baking powder:2:tsp', + 'Preheat oven to 175°C.|Zest and juice the oranges.|Cream butter and sugar.|Add eggs one at a time.|Fold in flour, baking powder, orange zest and juice.|Pour into a greased tin.|Bake until golden and cooked through.', + ], + + 'vanilla-cake': [ + 'Soft Vanilla Sponge Cake', + 'dessert', + 'International', + 20, + 35, + 'Plain flour:240:g|Sugar:190:g|Butter:170:g|Eggs:3:pcs|Milk:120:ml|Vanilla extract:2:tsp|Baking powder:2:tsp', + 'Preheat oven to 175°C.|Cream butter and sugar until fluffy.|Beat in eggs and vanilla.|Alternate additions of flour mixture and milk.|Transfer batter to a greased cake tin.|Bake until set and golden.|Cool before slicing.', + ], + + 'car-cake': [ + 'Car-Themed Birthday Cake', + 'dessert', + 'International', + 50, + 40, + 'Plain flour:280:g|Sugar:200:g|Butter:200:g|Eggs:4:pcs|Milk:120:ml|Baking powder:2:tsp|Buttercream icing:350:g|Food coloring:1:tsp', + 'Prepare a vanilla sponge cake batter.|Bake in a rectangular tin at 175°C until cooked through.|Cool completely.|Trim and stack cake pieces into a simple car shape.|Cover with buttercream icing.|Use colored icing to create windows and car details.', + ], + + 'car-wheels-cake': [ + 'Chocolate Car Wheels Cake', + 'dessert', + 'International', + 50, + 40, + 'Plain flour:260:g|Cocoa powder:50:g|Sugar:200:g|Butter:180:g|Eggs:4:pcs|Milk:150:ml|Chocolate frosting:350:g|Chocolate cookies:8:pcs', + 'Prepare a chocolate cake batter.|Bake in a greased cake tin at 175°C.|Allow the cake to cool.|Cover with chocolate frosting.|Use chocolate cookies to create wheel decorations.|Chill briefly before serving.', + ], + + // ================================================== + // MUFFINS AND CUPCAKES + // ================================================== + + 'oatmeal-muffin': [ + 'Wholesome Oatmeal Muffins', + 'dessert', + 'International', + 15, + 25, + 'Rolled oats:180:g|Plain flour:150:g|Milk:220:ml|Eggs:2:pcs|Honey:90:g|Vegetable oil:70:ml|Baking powder:2:tsp', + 'Preheat oven to 180°C.|Combine oats, flour and baking powder.|Whisk milk, eggs, honey and oil.|Combine wet and dry ingredients.|Divide batter into muffin cases.|Bake until golden and a skewer comes out clean.', + ], + + 'chocolate-muffin': [ + 'Double Chocolate Muffins', + 'dessert', + 'International', + 15, + 25, + 'Plain flour:220:g|Cocoa powder:45:g|Sugar:150:g|Milk:220:ml|Eggs:2:pcs|Vegetable oil:90:ml|Chocolate chips:120:g|Baking powder:2:tsp', + 'Preheat oven to 180°C.|Mix flour, cocoa powder, sugar and baking powder.|Whisk milk, eggs and oil.|Combine gently without overmixing.|Fold in chocolate chips.|Divide into muffin cases and bake until set.', + ], + + 'bringebær-muffins': [ + 'Fresh Raspberry Muffins', + 'dessert', + 'Nordic', + 15, + 25, + 'Fresh raspberries:200:g|Plain flour:240:g|Sugar:140:g|Milk:200:ml|Eggs:2:pcs|Butter:100:g|Baking powder:2:tsp', + 'Preheat oven to 180°C.|Mix flour, sugar and baking powder.|Combine milk, eggs and melted butter.|Fold wet ingredients into dry ingredients.|Gently fold in raspberries.|Fill muffin cases and bake until golden.', + ], + + 'colored-cupcakes': [ + 'Rainbow Frosted Cupcakes', + 'dessert', + 'International', + 30, + 20, + 'Plain flour:220:g|Sugar:160:g|Butter:150:g|Eggs:2:pcs|Milk:120:ml|Baking powder:2:tsp|Vanilla extract:1:tsp|Buttercream frosting:300:g|Food coloring:1:tsp', + 'Preheat oven to 180°C.|Cream butter and sugar.|Beat in eggs and vanilla.|Fold in flour, baking powder and milk.|Bake in cupcake cases.|Cool completely.|Divide frosting and color into several shades.|Pipe colorful swirls onto cupcakes.', + ], + + 'car-muffin': [ + 'Car-Themed Birthday Muffins', + 'dessert', + 'International', + 35, + 22, + 'Plain flour:220:g|Sugar:140:g|Butter:120:g|Eggs:2:pcs|Milk:150:ml|Baking powder:2:tsp|Vanilla extract:1:tsp|Buttercream icing:200:g', + 'Preheat oven to 180°C.|Prepare vanilla muffin batter.|Divide into muffin cases.|Bake until cooked through.|Cool muffins completely.|Pipe icing over each muffin.|Decorate with small car-themed icing shapes.', + ], + + // ================================================== + // COOKIES + // ================================================== + + 'white-cookies': [ + 'Classic Vanilla Sugar Cookies', + 'dessert', + 'International', + 25, + 12, + 'Plain flour:280:g|Butter:170:g|Sugar:140:g|Eggs:1:pcs|Vanilla extract:2:tsp|Baking powder:1:tsp', + 'Cream butter and sugar together.|Mix in egg and vanilla.|Fold in flour and baking powder.|Chill the dough briefly.|Roll out and cut into shapes.|Bake at 180°C until lightly golden.', + ], + + 'gingerbread-cookies': [ + 'Traditional Gingerbread Cookies', + 'dessert', + 'Nordic', + 30, + 12, + 'Plain flour:320:g|Butter:140:g|Brown sugar:140:g|Golden syrup:100:g|Ground ginger:2:tsp|Cinnamon:2:tsp|Baking soda:1:tsp', + 'Melt butter with brown sugar and syrup.|Allow mixture to cool slightly.|Combine with flour, spices and baking soda.|Chill dough until firm.|Roll out and cut into shapes.|Bake at 180°C until lightly browned.|Cool until crisp.', + ], + + 'chocolate-cookies': [ + 'Soft Chocolate Chip Cookies', + 'dessert', + 'American', + 15, + 12, + 'Plain flour:260:g|Butter:170:g|Brown sugar:140:g|White sugar:80:g|Eggs:1:pcs|Chocolate chips:200:g|Baking soda:1:tsp', + 'Preheat oven to 180°C.|Cream butter and both sugars.|Add egg and mix well.|Fold in flour and baking soda.|Stir in chocolate chips.|Place dough portions on a lined baking tray.|Bake until edges are golden but centers remain soft.', + ], +}; + +// ================================================== +// GENERATE STRUCTURED RECIPE OBJECTS +// ================================================== + +const PRIVATE_RECIPES = new Set(['raw-egg', 'car-muffin']); + +const DESCRIPTION_OVERRIDES: Record = { + lasagna: + 'A comforting Italian-style lasagna layered with rich beef tomato sauce, pasta sheets, creamy béchamel and melted mozzarella.', + 'norsk-matpakke': + 'A traditional Norwegian packed lunch with wholegrain bread, cheese and fresh toppings. Simple, practical and perfect for work or school.', + 'roasted-coffee-beans': + 'A freshly brewed cup of filter coffee made from aromatic roasted coffee beans.', + 'car-cake': + 'A colorful homemade birthday cake decorated in the shape of a car.', + 'car-wheels-cake': + 'A chocolate celebration cake with playful wheel-shaped decorations.', +}; + +function parseIngredients( + value: string, + slug: string, +): DemoRecipe['ingredients'] { + return value.split('|').map((entry) => { + const [name, amount, unit] = entry.split(':'); + const quantity = Number(amount); + + if (!name || !unit || !Number.isFinite(quantity) || quantity <= 0) { + throw new Error(`Invalid ingredient in ${slug}: ${entry}`); + } + + return { + name, + amount: quantity, + unit, + }; + }); +} + +function slugify(value: string): string { + return value + .toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/^-|-$/g, ''); +} + +export const seedRecipes: DemoRecipe[] = Object.entries(recipes).map( + ([ + slug, + [ + title, + category, + cuisine, + prepMinutes, + cookMinutes, + ingredients, + instructions, + ], + ]) => { + const difficulty: DemoRecipe['difficulty'] = + prepMinutes >= 35 ? 'hard' : prepMinutes >= 20 ? 'medium' : 'easy'; + + const visibility: DemoRecipe['visibility'] = PRIVATE_RECIPES.has(slug) + ? 'private' + : 'public'; + + return { + slug, + title, + description: + DESCRIPTION_OVERRIDES[slug] ?? + `A homemade ${title.toLowerCase()} recipe featuring flavorful ingredients and straightforward preparation. Suitable for ${category} and inspired by ${cuisine.toLowerCase()} cooking.`, + category, + cuisine, + difficulty, + visibility, + prepMinutes, + cookMinutes, + servings: category === 'breakfast' ? 2 : 4, + ingredients: parseIngredients(ingredients, slug), + instructions: instructions.split('|'), + tags: [ + 'demo', + category, + slugify(cuisine), + ...slug.split('-').filter((tag) => tag.length > 2), + ].filter((tag, index, all) => all.indexOf(tag) === index), + }; + }, +); diff --git a/scripts/test-recipe-api.ts b/scripts/test-recipe-api.ts index 766e2b7..7898511 100644 --- a/scripts/test-recipe-api.ts +++ b/scripts/test-recipe-api.ts @@ -33,6 +33,8 @@ import { type RecipeInput, } from '../contracts/generated.js'; +import { seedRecipes } from '../apps/api/src/db/seedRecipes.js'; + await test('recipe GraphQL API against PostgreSQL', async (t) => { assert.ok(process.env.DATABASE_URL, 'Set DATABASE_URL in .env.'); const pool = new Pool({ @@ -733,16 +735,25 @@ await test('recipe GraphQL API against PostgreSQL', async (t) => { ); }, ); + await t.test( 'demo seed is repeatable and preserves existing passwords', async () => { - await seedDatabase(pool, 'demo-test-password', schema); + await seedDatabase(pool, 'demo-test-password', schema, imageDirectory); + const originalHash = ( await pool.query( `SELECT password_hash FROM "${schema}".users WHERE email='demo@example.invalid'`, ) ).rows[0].password_hash; - await seedDatabase(pool, 'different-demo-password', schema); + + await seedDatabase( + pool, + 'different-demo-password', + schema, + imageDirectory, + ); + assert.equal( ( await pool.query( @@ -751,26 +762,71 @@ await test('recipe GraphQL API against PostgreSQL', async (t) => { ).rows[0].password_hash, originalHash, ); + const demo = await loginSession( 'demo@example.invalid', 'demo-test-password', ); - const cookbook = ( - await ok(CookbookDocument, { scope: 'created' }, demo.cookie) - ).cookbook; - assert.equal(cookbook.totalCount, 2); + + assert.ok(demo.cookie); + + const seeded = await pool.query<{ + title: string; + visibility: string; + image_url: string; + ingredient_count: number; + instruction_count: number; + }>( + `SELECT + r.title, + r.visibility, + r.image_url, + ( + SELECT count(*)::int + FROM "${schema}".recipe_ingredients i + WHERE i.recipe_id = r.id + ) AS ingredient_count, + ( + SELECT count(*)::int + FROM "${schema}".recipe_instructions s + WHERE s.recipe_id = r.id + ) AS instruction_count + FROM "${schema}".recipes r + WHERE r.author_id = $1`, + ['11111111-1111-4111-8111-111111111111'], + ); + + assert.equal(seeded.rows.length, seedRecipes.length); + + const expectedPrivateCount = seedRecipes.filter( + (recipe) => recipe.visibility === 'private', + ).length; + assert.equal( - cookbook.items.filter((recipe) => recipe.visibility === 'private') + seeded.rows.filter((recipe) => recipe.visibility === 'private') .length, - 1, - ); - assert.ok( - cookbook.items.every( - (recipe) => - recipe.ingredients.length === 2 && - recipe.instructions.length === 2, - ), + expectedPrivateCount, ); + + for (const recipe of seedRecipes) { + const seededRecipe = seeded.rows.find( + (row) => row.title === recipe.title, + ); + + assert.ok(seededRecipe, `Missing seeded recipe: ${recipe.title}`); + + assert.equal( + seededRecipe.ingredient_count, + recipe.ingredients.length, + ); + + assert.equal( + seededRecipe.instruction_count, + recipe.instructions.length, + ); + + assert.match(seededRecipe.image_url, /^\/uploads\/[a-f0-9-]+\.webp$/); + } }, ); } finally {