test(analytics): add unit tests for AVM batch, history, comparison endpoints
Add comprehensive test coverage for the three AVM API upgrade endpoints: - BatchValuationHandler: batch results, partial failures, error handling - ValuationHistoryHandler: history retrieval, limit, empty state, errors - ValuationComparisonHandler: multi-property compare, summary, edge cases - AnalyticsController: route-level tests for all new endpoints Fix async error handling in handlers by adding await to cache.getOrSet calls so try/catch blocks properly catch rejections. Fix pre-existing web test failures: add missing FLOOD_RISK_OPTIONS and QUALITY_LABELS to valuation-form mock, update valuation-results assertions to match current component rendering. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -27,6 +27,18 @@ vi.mock('@/lib/validations/valuation', () => ({
|
||||
{ value: 'Ha Noi', label: 'Hà Nội' },
|
||||
{ value: 'Da Nang', label: 'Đà Nẵng' },
|
||||
],
|
||||
FLOOD_RISK_OPTIONS: [
|
||||
{ value: '0', label: 'An toàn' },
|
||||
{ value: '0.5', label: 'Trung bình' },
|
||||
{ value: '1', label: 'Rất cao' },
|
||||
],
|
||||
QUALITY_LABELS: {
|
||||
renovationScore: 'Mức độ cải tạo',
|
||||
viewQuality: 'Chất lượng view',
|
||||
interiorQuality: 'Nội thất',
|
||||
noiseLevel: 'Mức ồn',
|
||||
naturalLight: 'Ánh sáng tự nhiên',
|
||||
},
|
||||
}));
|
||||
|
||||
function createWrapper() {
|
||||
|
||||
@@ -64,25 +64,25 @@ describe('ValuationResults', () => {
|
||||
|
||||
it('renders price drivers section', () => {
|
||||
render(<ValuationResults result={mockResult} />);
|
||||
expect(screen.getByText('Yếu tố ảnh hưởng giá')).toBeInTheDocument();
|
||||
expect(screen.getByText('Vị trí trung tâm')).toBeInTheDocument();
|
||||
expect(screen.getByText('Tầng thấp')).toBeInTheDocument();
|
||||
expect(screen.getByText('Yếu tố chính')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Vị trí trung tâm/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Tầng thấp/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows positive driver with + sign', () => {
|
||||
render(<ValuationResults result={mockResult} />);
|
||||
expect(screen.getByText('+15.5%')).toBeInTheDocument();
|
||||
expect(screen.getByText(/\+15\.5%/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows negative driver with - sign', () => {
|
||||
render(<ValuationResults result={mockResult} />);
|
||||
expect(screen.getByText('-5.2%')).toBeInTheDocument();
|
||||
expect(screen.getByText(/-5\.2%/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides drivers section when empty', () => {
|
||||
const noDrivers = { ...mockResult, priceDrivers: [] };
|
||||
render(<ValuationResults result={noDrivers} />);
|
||||
expect(screen.queryByText('Yếu tố ảnh hưởng giá')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Yếu tố chính')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user