import { describe, expect, it } from 'bun:test';
import { plannedOutcome, servicesNeedingMemberProvision } from './members';
import { byId } from './catalogue';

describe('what adding a member would do', () => {
  it('predicts the outcome per service without contacting anything', () => {
    expect(plannedOutcome(byId('photos')!)).toBe('provisioned');
    expect(plannedOutcome(byId('vault')!)).toBe('invited');
    expect(plannedOutcome(byId('transmission')!)).toBe('not-applicable');
  });
});

describe('which installed services have work to do', () => {
  it('skips single-tenant daemons entirely', () => {
    const ids = servicesNeedingMemberProvision(['photos', 'transmission', 'slskd', 'vault']).map((e) => e.id);
    expect(ids.sort()).toEqual(['photos', 'vault']);
  });

  it('ignores services that are not installed', () => {
    // The catalogue is what COULD be installed; only what IS installed has a member to provision.
    expect(servicesNeedingMemberProvision([])).toEqual([]);
    expect(servicesNeedingMemberProvision(['jellyfin']).map((e) => e.id)).toEqual(['jellyfin']);
  });
});
