feat: getBurndownData helper + computeBurndownDays (lib/insights/burndown.ts) (#34)
Server-side aggregatie per active sprint: bouwt time-series met remaining en ideal per dag. Inclusief 4 Vitest-unit-tests voor de pure computeBurndownDays functie. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
79c9661ebd
commit
fb3e55b9c0
2 changed files with 144 additions and 0 deletions
57
__tests__/lib/insights/burndown.test.ts
Normal file
57
__tests__/lib/insights/burndown.test.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
vi.mock('@/lib/prisma', () => ({ prisma: {} }))
|
||||
|
||||
import { computeBurndownDays } from '@/lib/insights/burndown'
|
||||
|
||||
describe('computeBurndownDays', () => {
|
||||
it('5-day sprint: remaining and ideal match spec', () => {
|
||||
const start = new Date('2024-01-01T00:00:00.000Z')
|
||||
const end = new Date('2024-01-05T00:00:00.000Z')
|
||||
|
||||
const tasks = [
|
||||
{ status: 'DONE', updated_at: new Date('2024-01-02T12:00:00.000Z') },
|
||||
{ status: 'DONE', updated_at: new Date('2024-01-04T12:00:00.000Z') },
|
||||
{ status: 'IN_PROGRESS', updated_at: new Date('2024-01-05T12:00:00.000Z') },
|
||||
]
|
||||
|
||||
const days = computeBurndownDays(tasks, start, end)
|
||||
|
||||
expect(days).toHaveLength(5)
|
||||
expect(days.map(d => d.remaining)).toEqual([3, 2, 2, 1, 1])
|
||||
expect(days.map(d => d.ideal)).toEqual([3, 2.25, 1.5, 0.75, 0])
|
||||
expect(days.map(d => d.day)).toEqual([
|
||||
'2024-01-01',
|
||||
'2024-01-02',
|
||||
'2024-01-03',
|
||||
'2024-01-04',
|
||||
'2024-01-05',
|
||||
])
|
||||
})
|
||||
|
||||
it('returns empty array when end is before start', () => {
|
||||
const start = new Date('2024-01-05T00:00:00.000Z')
|
||||
const end = new Date('2024-01-01T00:00:00.000Z')
|
||||
expect(computeBurndownDays([], start, end)).toEqual([])
|
||||
})
|
||||
|
||||
it('single-day sprint has ideal = 0', () => {
|
||||
const day = new Date('2024-01-01T00:00:00.000Z')
|
||||
const tasks = [{ status: 'TO_DO', updated_at: new Date('2024-01-01T08:00:00.000Z') }]
|
||||
const days = computeBurndownDays(tasks, day, day)
|
||||
expect(days).toHaveLength(1)
|
||||
expect(days[0].ideal).toBe(0)
|
||||
expect(days[0].remaining).toBe(1)
|
||||
})
|
||||
|
||||
it('all tasks done on first day: remaining drops to 0', () => {
|
||||
const start = new Date('2024-01-01T00:00:00.000Z')
|
||||
const end = new Date('2024-01-03T00:00:00.000Z')
|
||||
const tasks = [
|
||||
{ status: 'DONE', updated_at: new Date('2024-01-01T10:00:00.000Z') },
|
||||
{ status: 'DONE', updated_at: new Date('2024-01-01T11:00:00.000Z') },
|
||||
]
|
||||
const days = computeBurndownDays(tasks, start, end)
|
||||
expect(days.map(d => d.remaining)).toEqual([0, 0, 0])
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue