Files
parenthese/backend/test/sibling-order.test.ts
T
IliesAllaliandClaude Opus 5.5 588ac0c4e9 API : un nouvel enfant se place après ses frères et soeurs
Sans ordre fourni, un lien parent-enfant créé (route, contribution, import
GEDCOM) prend l'ordre suivant celui de la fratrie, pour qu'un enfant ajouté
après un réordonnancement ne passe pas devant les autres.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 18:53:23 +02:00

26 lines
950 B
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { nextSiblingOrder } from '../src/lib/sibling-order.js'
function dbReturning(last: { displayOrder: number } | null) {
const findFirst = vi.fn().mockResolvedValue(last)
return { db: { parentChildLink: { findFirst } } as any, findFirst }
}
describe('nextSiblingOrder', () => {
it('places a new child after the last sibling of the parent', async () => {
const { db, findFirst } = dbReturning({ displayOrder: 3 })
await expect(nextSiblingOrder(db, 'tree-1', 'parent-1')).resolves.toBe(4)
expect(findFirst).toHaveBeenCalledWith({
where: { treeId: 'tree-1', parentPersonId: 'parent-1', deletedAt: null },
orderBy: { displayOrder: 'desc' },
select: { displayOrder: true },
})
})
it('starts at 1 for a first child', async () => {
const { db } = dbReturning(null)
await expect(nextSiblingOrder(db, 'tree-1', 'parent-1')).resolves.toBe(1)
})
})