mirror of
https://github.com/complexcaresolutions/cms.c2sgmbh.git
synced 2026-03-17 17:24:12 +00:00
Adds a capacity calculator utility and API endpoint that computes workload utilization for team members with YouTube roles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
143 lines
3.5 KiB
TypeScript
143 lines
3.5 KiB
TypeScript
/**
|
|
* Team Capacity Calculator Unit Tests
|
|
*
|
|
* Tests utilization calculation and status thresholds
|
|
* used by the capacity API route.
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
import { calculateCapacity, type CapacityInput } from '@/lib/youtube/capacity-calculator'
|
|
|
|
describe('Capacity Calculator', () => {
|
|
it('should calculate utilization percentage', () => {
|
|
const input: CapacityInput = {
|
|
userId: 1,
|
|
userName: 'Max',
|
|
activeTasks: 5,
|
|
estimatedHours: 20,
|
|
videosInPipeline: 3,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(50)
|
|
expect(result.status).toBe('green')
|
|
})
|
|
|
|
it('should flag overloaded team members as red', () => {
|
|
const input: CapacityInput = {
|
|
userId: 2,
|
|
userName: 'Anna',
|
|
activeTasks: 10,
|
|
estimatedHours: 38,
|
|
videosInPipeline: 8,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(95)
|
|
expect(result.status).toBe('red')
|
|
})
|
|
|
|
it('should flag busy team members as yellow', () => {
|
|
const input: CapacityInput = {
|
|
userId: 3,
|
|
userName: 'Lisa',
|
|
activeTasks: 8,
|
|
estimatedHours: 32,
|
|
videosInPipeline: 5,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(80)
|
|
expect(result.status).toBe('yellow')
|
|
})
|
|
|
|
it('should handle zero available hours', () => {
|
|
const input: CapacityInput = {
|
|
userId: 4,
|
|
userName: 'Tom',
|
|
activeTasks: 3,
|
|
estimatedHours: 10,
|
|
videosInPipeline: 2,
|
|
availableHoursPerWeek: 0,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(0)
|
|
expect(result.status).toBe('green')
|
|
})
|
|
|
|
it('should preserve all input fields in the result', () => {
|
|
const input: CapacityInput = {
|
|
userId: 5,
|
|
userName: 'Sara',
|
|
activeTasks: 4,
|
|
estimatedHours: 16,
|
|
videosInPipeline: 2,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.userId).toBe(5)
|
|
expect(result.userName).toBe('Sara')
|
|
expect(result.activeTasks).toBe(4)
|
|
expect(result.estimatedHours).toBe(16)
|
|
expect(result.videosInPipeline).toBe(2)
|
|
expect(result.availableHoursPerWeek).toBe(40)
|
|
})
|
|
|
|
it('should return red for utilization over 100%', () => {
|
|
const input: CapacityInput = {
|
|
userId: 6,
|
|
userName: 'Overloaded',
|
|
activeTasks: 30,
|
|
estimatedHours: 60,
|
|
videosInPipeline: 10,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(150)
|
|
expect(result.status).toBe('red')
|
|
})
|
|
|
|
it('should return green at exactly 70% utilization', () => {
|
|
const input: CapacityInput = {
|
|
userId: 7,
|
|
userName: 'Boundary70',
|
|
activeTasks: 7,
|
|
estimatedHours: 28,
|
|
videosInPipeline: 3,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(70)
|
|
expect(result.status).toBe('green')
|
|
})
|
|
|
|
it('should return yellow at exactly 90% utilization', () => {
|
|
const input: CapacityInput = {
|
|
userId: 8,
|
|
userName: 'Boundary90',
|
|
activeTasks: 9,
|
|
estimatedHours: 36,
|
|
videosInPipeline: 4,
|
|
availableHoursPerWeek: 40,
|
|
}
|
|
|
|
const result = calculateCapacity(input)
|
|
|
|
expect(result.utilization).toBe(90)
|
|
expect(result.status).toBe('yellow')
|
|
})
|
|
})
|