Tofu/scripts/import-recipes/tests/listIngredientNames.test.js
2026-09-18 01:41:02 +02:00

31 lines
1.1 KiB
JavaScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { listIngredientNames } from '#import-recipes/recipes/listIngredientNames.js'
function buildDocument(parsedIngredients) {
return { name: 'Gratin', 'tofu:parsedIngredients': parsedIngredients }
}
test('lists the names in document order', () => {
const document = buildDocument([
{ name: 'gnocchis' },
{ name: 'beurre' },
{ name: 'sauge' },
{ name: 'parmesan' }
])
assert.deepEqual(listIngredientNames(document), ['gnocchis', 'beurre', 'sauge', 'parmesan'])
})
test('keeps the first spelling and drops repeats, accents aside', () => {
const document = buildDocument([{ name: 'Crème' }, { name: 'creme' }, { name: 'CRÈME' }])
assert.deepEqual(listIngredientNames(document), ['Crème'])
})
test('trims and skips empty names', () => {
const document = buildDocument([{ name: ' sel ' }, { name: '' }, { name: null }])
assert.deepEqual(listIngredientNames(document), ['sel'])
})
test('returns an empty list when the document holds no split', () => {
assert.deepEqual(listIngredientNames({ name: 'Gratin' }), [])
})