import { describe, expect, it } from 'vitest'; import { MOD_SECONDARY_CAPACITY, normalizeModSecondaryPool, } from './secondary-pool'; const endpoints = ( level1Min: number | string, level1Max: number | string, level20Min: number | string, level20Max: number | string, ) => ({ level1Min, level1Max, level20Min, level20Max }); const range = (statId: string) => ({ statId, values: { Specialized: endpoints('1.5', '2.5', '3.5', '4.5'), Superior: endpoints(2, 3, 4, 5), 'High-end': endpoints(3, 4, 5, 6), }, }); describe('shared Mod secondary pool', () => { it('defines secondary capacity for every Mod quality', () => { expect(MOD_SECONDARY_CAPACITY).toEqual({ Standard: 0, Specialized: 1, Superior: 2, 'High-end': 2, }); }); it('normalizes Attribute IDs and valid Level 1/20 endpoints', () => { const result = normalizeModSecondaryPool([ range(' critical-hit-chance '), range('critical-hit-damage'), ]); expect(result.error).toBeNull(); expect(result.pool).toEqual([ { statId: 'critical-hit-chance', values: { Specialized: endpoints(1.5, 2.5, 3.5, 4.5), Superior: endpoints(2, 3, 4, 5), 'High-end': endpoints(3, 4, 5, 6), }, }, { statId: 'critical-hit-damage', values: { Specialized: endpoints(1.5, 2.5, 3.5, 4.5), Superior: endpoints(2, 3, 4, 5), 'High-end': endpoints(3, 4, 5, 6), }, }, ]); }); it('rejects duplicate Attributes after ID normalization', () => { const result = normalizeModSecondaryPool([ range('critical-hit-chance'), range(' critical-hit-chance '), ]); expect(result).toEqual({ pool: [], error: 'Choose a unique Attribute for every shared pool option.', }); }); it.each([ [ 'missing quality ranges', { ...range('critical-hit-chance'), values: { Specialized: endpoints(1, 2, 3, 4), Superior: endpoints(2, 3, 4, 5), }, }, ], [ 'reversed ranges', { ...range('critical-hit-chance'), values: { ...range('critical-hit-chance').values, Specialized: endpoints(2, 1, 3, 4), }, }, ], [ 'Level 20 regression', { ...range('critical-hit-chance'), values: { ...range('critical-hit-chance').values, Specialized: endpoints(2, 3, 1, 2), }, }, ], ])('rejects %s', (_label, invalidRange) => { const result = normalizeModSecondaryPool([ invalidRange, range('critical-hit-damage'), ]); expect(result).toEqual({ pool: [], error: 'Configure valid Level 1 and Level 20 ranges for Specialized, Superior, and High-end quality.', }); }); });