import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getScopeChildren } from '@/shared/api/scope';
import { apiRequest } from '@/shared/api/httpClient';

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

const apiRequestMock = vi.mocked(apiRequest);

describe('scope API', () => {
  beforeEach(() => {
    apiRequestMock.mockReset();
  });

  it('fetches scope children without parameters', () => {
    void getScopeChildren();

    expect(apiRequestMock).toHaveBeenCalledWith('/scope/children');
  });

  it('fetches scope children with parent level', () => {
    void getScopeChildren('organization');

    expect(apiRequestMock).toHaveBeenCalledWith('/scope/children?parentLevel=organization');
  });

  it('fetches scope children with parent level and id', () => {
    void getScopeChildren('school', 'school-123');

    expect(apiRequestMock).toHaveBeenCalledWith('/scope/children?parentLevel=school&parentId=school-123');
  });

  it('fetches scope children with an explicit limit', () => {
    void getScopeChildren('school', 'school-123', { limit: 1000 });

    expect(apiRequestMock).toHaveBeenCalledWith('/scope/children?parentLevel=school&parentId=school-123&limit=1000');
  });
});
