19 lines
739 B
JavaScript
19 lines
739 B
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { makeUniqueRecipeId } from '#import-recipes/recipes/makeUniqueRecipeId.js'
|
|
|
|
test('keeps the id when it is free', () => {
|
|
assert.equal(makeUniqueRecipeId('tarte-aux-pommes', []), 'tarte-aux-pommes')
|
|
assert.equal(makeUniqueRecipeId('tarte-aux-pommes', ['gratin']), 'tarte-aux-pommes')
|
|
})
|
|
|
|
test('numbers the id when it is taken', () => {
|
|
assert.equal(makeUniqueRecipeId('gratin', ['gratin']), 'gratin-2')
|
|
assert.equal(makeUniqueRecipeId('gratin', ['gratin', 'gratin-2']), 'gratin-3')
|
|
})
|
|
|
|
test('does not mutate the list it is given', () => {
|
|
const usedIds = ['gratin']
|
|
makeUniqueRecipeId('gratin', usedIds)
|
|
assert.deepEqual(usedIds, ['gratin'])
|
|
})
|