import { describe, it, expect } from 'vitest'
import { isOrphanUser } from '../orphan'

// KAR-787 / R3: a user is an "orphan" when their account is not linked to any
// consultant (Mitarbeiter) record — i.e. no consultant carries their auth id.

describe('isOrphanUser (R3)', () => {
  const linked = new Set(['auth-1', 'auth-2'])

  it('is false when the auth id is linked to a consultant', () => {
    expect(isOrphanUser('auth-1', linked)).toBe(false)
  })

  it('is true when the auth id is not in the linked set', () => {
    expect(isOrphanUser('auth-9', linked)).toBe(true)
  })

  it('is true when the user has no auth id at all', () => {
    expect(isOrphanUser(null, linked)).toBe(true)
    expect(isOrphanUser(undefined, linked)).toBe(true)
    expect(isOrphanUser('', linked)).toBe(true)
  })

  it('is true against an empty linked set', () => {
    expect(isOrphanUser('auth-1', new Set())).toBe(true)
  })
})
