Initial commit of counter
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { generatePlan, styleAllows } = require('../server/planner');
|
||||
const { RECIPES } = require('../server/seed');
|
||||
|
||||
test('a plan covers every meal slot with distinct recipes', () => {
|
||||
const plan = generatePlan({
|
||||
date: '2026-11-07', targetKcal: 2200, proteinTarget: 140, style: 'any', recipes: RECIPES,
|
||||
});
|
||||
|
||||
assert.deepEqual(plan.items.map((item) => item.meal), ['breakfast', 'lunch', 'dinner', 'snack']);
|
||||
assert.equal(new Set(plan.items.map((item) => item.id)).size, 4);
|
||||
assert.ok(plan.totals.kcal > 1500 && plan.totals.kcal < 3000, `plan was ${plan.totals.kcal} kcal`);
|
||||
});
|
||||
|
||||
test('the same date always generates the same plan', () => {
|
||||
const args = {
|
||||
date: '2026-11-07', targetKcal: 2000, proteinTarget: 120, style: 'any', recipes: RECIPES,
|
||||
};
|
||||
assert.deepEqual(
|
||||
generatePlan(args).items.map((item) => item.id),
|
||||
generatePlan(args).items.map((item) => item.id)
|
||||
);
|
||||
});
|
||||
|
||||
test('a vegan plan only contains vegan recipes', () => {
|
||||
const plan = generatePlan({
|
||||
date: '2026-11-07', targetKcal: 2000, proteinTarget: 100, style: 'vegan', recipes: RECIPES,
|
||||
});
|
||||
assert.equal(plan.items.length, 4);
|
||||
assert.ok(plan.items.every((item) => item.tags.includes('vegan')));
|
||||
});
|
||||
|
||||
test('a high-protein plan favours protein-rich recipes', () => {
|
||||
const plan = generatePlan({
|
||||
date: '2026-11-07', targetKcal: 2000, proteinTarget: 160, style: 'high_protein', recipes: RECIPES,
|
||||
});
|
||||
assert.ok(plan.totals.protein_g > 100);
|
||||
});
|
||||
|
||||
test('style filtering falls back to any recipe when nothing matches', () => {
|
||||
const onlySnack = RECIPES.filter((recipe) => recipe.meal === 'snack' && recipe.tags.includes('vegan'));
|
||||
const plan = generatePlan({
|
||||
date: '2026-11-07', targetKcal: 1800, proteinTarget: 90, style: 'vegetarian', recipes: onlySnack,
|
||||
});
|
||||
assert.ok(plan.items.length >= 1);
|
||||
});
|
||||
|
||||
test('styleAllows treats vegan as vegetarian and high protein by macro', () => {
|
||||
assert.equal(styleAllows({ tags: ['vegan'], protein_g: 10 }, 'vegetarian'), true);
|
||||
assert.equal(styleAllows({ tags: [], protein_g: 30 }, 'high_protein'), true);
|
||||
assert.equal(styleAllows({ tags: ['vegetarian'], protein_g: 10 }, 'vegan'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user