import { describe, expect, it, vi } from 'vitest';
import { getClassAttendanceSummary, upsertClassAttendance } from '@/shared/api/classAttendance';
import { apiRequest } from '@/shared/api/httpClient';

vi.mock('@/shared/api/httpClient', () => ({
  apiRequest: vi.fn(),
}));

describe('class attendance API', () => {
  it('lists attendance summary with optional dates', async () => {
    vi.mocked(apiRequest).mockResolvedValueOnce({ rows: [] });

    await getClassAttendanceSummary('2026-06-01', '2026-06-15');

    expect(apiRequest).toHaveBeenCalledWith('/class_attendance/summary?startDate=2026-06-01&endDate=2026-06-15');
  });

  it('upserts class attendance totals', async () => {
    vi.mocked(apiRequest).mockResolvedValueOnce({});

    await upsertClassAttendance('class-1', '2026-06-15', {
      total_enrolled: 10,
      total_present: 9,
      total_absent: 1,
      total_tardy: 0,
    });

    expect(apiRequest).toHaveBeenCalledWith('/class_attendance/class-1/2026-06-15', {
      method: 'PUT',
      body: {
        data: {
          total_enrolled: 10,
          total_present: 9,
          total_absent: 1,
          total_tardy: 0,
        },
      },
    });
  });
});
