const test = require("node:test"); const assert = require("node:assert/strict"); const { flattenInstructions, updateProgress } = require("../lib/recipe-progress"); const recipe = { recipeIngredient: ["1 cup flour", "1 egg"], recipeInstructions: ["Mix", { itemListElement: [{ text: "Bake" }] }] }; test("flattens nested recipe instructions", () => { assert.deepEqual(flattenInstructions(recipe.recipeInstructions), ["Mix", "Bake"]); }); test("updates and validates cooking progress", () => { const ingredientProgress = updateProgress(recipe, {}, { kind: "ingredient", index: 1, completed: true }); assert.deepEqual(ingredientProgress, { completedIngredients: [1], completedSteps: [] }); assert.deepEqual(updateProgress(recipe, ingredientProgress, { kind: "ingredient", index: 1, completed: false }), { completedIngredients: [], completedSteps: [] }); assert.throws(() => updateProgress(recipe, {}, { kind: "step", index: 2, completed: true }), /does not exist/); });