|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | + |
| 3 | +import type { PrerequisiteCheckResult } from 'common' |
| 4 | + |
| 5 | +import { getPrerequisiteSummary } from './prerequisite-summary.js' |
| 6 | + |
| 7 | +const makeCheckResult = ( |
| 8 | + prerequisiteId: string, |
| 9 | + status: PrerequisiteCheckResult['status'], |
| 10 | +): PrerequisiteCheckResult => ({ |
| 11 | + prerequisiteId, |
| 12 | + status, |
| 13 | + output: '', |
| 14 | + checkedAt: '', |
| 15 | +}) |
| 16 | + |
| 17 | +describe('getPrerequisiteSummary', () => { |
| 18 | + it('should return null for empty prereqIds', () => { |
| 19 | + const result = getPrerequisiteSummary([], new Map()) |
| 20 | + expect(result).toBeNull() |
| 21 | + }) |
| 22 | + |
| 23 | + it('should return all satisfied when every prereq is satisfied', () => { |
| 24 | + const map = new Map<string, PrerequisiteCheckResult>([ |
| 25 | + ['p1', makeCheckResult('p1', 'satisfied')], |
| 26 | + ['p2', makeCheckResult('p2', 'satisfied')], |
| 27 | + ]) |
| 28 | + const result = getPrerequisiteSummary(['p1', 'p2'], map) |
| 29 | + expect(result).toEqual({ satisfiedCount: 2, failedCount: 0, total: 2 }) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should count failed prerequisites', () => { |
| 33 | + const map = new Map<string, PrerequisiteCheckResult>([ |
| 34 | + ['p1', makeCheckResult('p1', 'satisfied')], |
| 35 | + ['p2', makeCheckResult('p2', 'failed')], |
| 36 | + ['p3', makeCheckResult('p3', 'failed')], |
| 37 | + ]) |
| 38 | + const result = getPrerequisiteSummary(['p1', 'p2', 'p3'], map) |
| 39 | + expect(result).toEqual({ satisfiedCount: 1, failedCount: 2, total: 3 }) |
| 40 | + }) |
| 41 | + |
| 42 | + it('should treat missing map entries as unchecked (neither satisfied nor failed)', () => { |
| 43 | + const map = new Map<string, PrerequisiteCheckResult>([['p1', makeCheckResult('p1', 'satisfied')]]) |
| 44 | + const result = getPrerequisiteSummary(['p1', 'p2'], map) |
| 45 | + expect(result).toEqual({ satisfiedCount: 1, failedCount: 0, total: 2 }) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should treat "checking" and "unchecked" statuses as neither satisfied nor failed', () => { |
| 49 | + const map = new Map<string, PrerequisiteCheckResult>([ |
| 50 | + ['p1', makeCheckResult('p1', 'checking')], |
| 51 | + ['p2', makeCheckResult('p2', 'unchecked')], |
| 52 | + ['p3', makeCheckResult('p3', 'satisfied')], |
| 53 | + ]) |
| 54 | + const result = getPrerequisiteSummary(['p1', 'p2', 'p3'], map) |
| 55 | + expect(result).toEqual({ satisfiedCount: 1, failedCount: 0, total: 3 }) |
| 56 | + }) |
| 57 | + |
| 58 | + it('should handle a mix of all statuses', () => { |
| 59 | + const map = new Map<string, PrerequisiteCheckResult>([ |
| 60 | + ['p1', makeCheckResult('p1', 'satisfied')], |
| 61 | + ['p2', makeCheckResult('p2', 'failed')], |
| 62 | + ['p3', makeCheckResult('p3', 'checking')], |
| 63 | + ['p4', makeCheckResult('p4', 'unchecked')], |
| 64 | + ]) |
| 65 | + const result = getPrerequisiteSummary(['p1', 'p2', 'p3', 'p4', 'p5'], map) |
| 66 | + expect(result).toEqual({ satisfiedCount: 1, failedCount: 1, total: 5 }) |
| 67 | + }) |
| 68 | +}) |
0 commit comments