Spaces:
Running
Running
| /** | |
| * Mandi Prices Routes Tests | |
| */ | |
| describe('Mandi Prices', () => { | |
| it('should generate price data for commodity', () => { | |
| const basePrice = 2200; // wheat | |
| const days = 30; | |
| const prices = Array.from({ length: days }, () => { | |
| const variation = (Math.random() - 0.5) * basePrice * 0.08; | |
| return Math.round(basePrice + variation); | |
| }); | |
| expect(prices).toHaveLength(30); | |
| prices.forEach(p => { | |
| expect(p).toBeGreaterThan(0); | |
| }); | |
| }); | |
| it('should calculate statistics correctly', () => { | |
| const prices = [2200, 2300, 2100, 2250, 2180]; | |
| const avg = Math.round(prices.reduce((a, b) => a + b, 0) / prices.length); | |
| const min = Math.min(...prices); | |
| const max = Math.max(...prices); | |
| const trend = prices[prices.length - 1] > prices[0] ? 'rising' : 'falling'; | |
| expect(avg).toBe(2206); | |
| expect(min).toBe(2100); | |
| expect(max).toBe(2300); | |
| expect(trend).toBe('falling'); | |
| }); | |
| it('should have valid commodity list', () => { | |
| const commodities = ['wheat', 'rice', 'groundnut', 'soybean', 'mustard', 'cotton']; | |
| expect(commodities.length).toBeGreaterThan(5); | |
| commodities.forEach(c => { | |
| expect(typeof c).toBe('string'); | |
| expect(c.length).toBeGreaterThan(0); | |
| }); | |
| }); | |
| it('should limit days to max 90', () => { | |
| const days = Math.min(parseInt('100'), 90); | |
| expect(days).toBe(90); | |
| }); | |
| }); | |