import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { ApiConfigService } from '../../config/api-config.service';
import { ApiBootstrapProvider } from './api-bootstrap.provider';

describe('ApiBootstrapProvider', () => {
  let provider: ApiBootstrapProvider;
  let httpTesting: HttpTestingController;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        ApiBootstrapProvider,
        provideHttpClient(),
        provideHttpClientTesting(),
        {
          provide: ApiConfigService,
          useValue: { getBaseUrl: () => 'https://api.gorbushka.market' }
        }
      ]
    });

    provider = TestBed.inject(ApiBootstrapProvider);
    httpTesting = TestBed.inject(HttpTestingController);
  });

  afterEach(() => httpTesting.verify());

  it('loads bootstrap from the same tenant API base as every other request', () => {
    provider.loadBootstrap().subscribe();

    const request = httpTesting.expectOne('https://api.gorbushka.market/bootstrap');
    expect(request.request.method).toBe('GET');
    request.flush({});
  });
});
