Files
ss-tools/frontend/tests/maintenance-api.test.ts
busya 31680a1bc9 fix(maintenance): auto-expiry + adaptive markdown height + tests
- Auto-expiry: expired events auto-end on GET /events via task manager
- Height: _estimate_markdown_height adapted to unit=8px scale with padding detection
- CRITICAL-1: removed dead import remove_chart_from_position (QA finding)
- CRITICAL-2: added chart alive check in ensure_banner_chart (QA finding)
- CRITICAL-3: fixed test assertions update_markdown_chart → update_banner_on_dashboard
- @POST contract: fixed return range [2,12] → [19,200]
- Tests: 8 new tests (auto-expiry + layout height)
2026-05-25 08:36:33 +03:00

43 lines
2.1 KiB
TypeScript

// #region MaintenanceApiTests [C:2] [TYPE Module] [SEMANTICS test, api, maintenance, url, contract]
// @BRIEF Verify that API client functions construct correct URLs (no double `/api/` etc.)
import { describe, it, expect, vi, beforeEach } from 'vitest';
const { mockRequestApi } = vi.hoisted(() => ({ mockRequestApi: vi.fn() }));
vi.mock('$lib/api.js', () => ({ requestApi: mockRequestApi }));
import { startMaintenance, endMaintenance, endAllMaintenance, getSettings, updateSettings, listEvents, listDashboardBanners } from '$lib/api/maintenance.js';
describe('MaintenanceApi URL construction', () => {
beforeEach(() => vi.clearAllMocks());
it('startMaintenance → POST /maintenance/start', async () => {
mockRequestApi.mockResolvedValue({ task_id: 't-1', maintenance_id: 'm-1', status: 'pending' });
await startMaintenance({ tables: ['raw.sales'], start_time: '2026-05-21T22:00:00Z', end_time: '2026-05-22T02:00:00Z' });
expect(mockRequestApi).toHaveBeenCalledWith('/maintenance/start', 'POST', expect.any(Object));
});
it('endMaintenance → POST /maintenance/{id}/end', async () => {
mockRequestApi.mockResolvedValue({ task_id: 't-1', status: 'pending' });
await endMaintenance('ev-abc');
expect(mockRequestApi).toHaveBeenCalledWith('/maintenance/ev-abc/end', 'POST');
});
it('endAllMaintenance → POST /maintenance/end-all', async () => {
mockRequestApi.mockResolvedValue({ task_id: 't-1', status: 'pending' });
await endAllMaintenance();
expect(mockRequestApi).toHaveBeenCalledWith('/maintenance/end-all', 'POST');
});
it('listEvents → GET /maintenance/events', async () => {
mockRequestApi.mockResolvedValue({ active: [], completed: [] });
await listEvents();
expect(mockRequestApi).toHaveBeenCalledWith('/maintenance/events', 'GET');
});
it('listDashboardBanners → GET /maintenance/dashboard-banners', async () => {
mockRequestApi.mockResolvedValue([]);
await listDashboardBanners();
expect(mockRequestApi).toHaveBeenCalledWith('/maintenance/dashboard-banners', 'GET');
});
});