import { TestBed } from '@angular/core/testing';

import { tenantBootstrap } from './tenant-bootstrap';
import { TenantService } from './tenant.service';

describe('tenantBootstrap', () => {
  it('waits for TenantService.bootstrap to resolve', async () => {
    const bootstrapSpy = vi.fn().mockResolvedValue(undefined);

    TestBed.configureTestingModule({
      providers: [
        {
          provide: TenantService,
          useValue: {
            bootstrap: bootstrapSpy
          }
        }
      ]
    });

    await expect(TestBed.runInInjectionContext(() => tenantBootstrap())).resolves.toBeUndefined();
    expect(bootstrapSpy).toHaveBeenCalledTimes(1);
  });

  it('propagates tenant bootstrap failures', async () => {
    const bootstrapSpy = vi.fn().mockRejectedValue(new Error('bootstrap failed'));

    TestBed.configureTestingModule({
      providers: [
        {
          provide: TenantService,
          useValue: {
            bootstrap: bootstrapSpy
          }
        }
      ]
    });

    await expect(TestBed.runInInjectionContext(() => tenantBootstrap())).rejects.toThrow(
      'bootstrap failed'
    );
    expect(bootstrapSpy).toHaveBeenCalledTimes(1);
  });
});
