import { describe, expect, it, vi } from 'vitest'
import { buildEnabledThirdPartyProviders } from '../auth/supertokens-client'

describe('buildEnabledThirdPartyProviders', () => {
  it('includes the bounded ORCID custom provider when that runtime flag is enabled', () => {
    const githubInit = vi.fn(() => ({ id: 'github' }))
    const googleInit = vi.fn(() => ({ id: 'google' }))

    const providers = buildEnabledThirdPartyProviders({
      githubEnabled: false,
      googleEnabled: false,
      orcidEnabled: true,
      Github: { init: githubInit },
      Google: { init: googleInit },
    })

    expect(providers).toEqual([{ id: 'orcid', name: 'ORCID' }])
    expect(githubInit).not.toHaveBeenCalled()
    expect(googleInit).not.toHaveBeenCalled()
  })

  it('preserves the built-in provider order while appending ORCID only when enabled', () => {
    const githubProvider = { id: 'github' }
    const googleProvider = { id: 'google' }
    const orcidProvider = { id: 'orcid', name: 'ORCID' }

    const providers = buildEnabledThirdPartyProviders({
      githubEnabled: true,
      googleEnabled: true,
      orcidEnabled: true,
      Github: { init: () => githubProvider },
      Google: { init: () => googleProvider },
    })

    expect(providers).toEqual([
      githubProvider,
      googleProvider,
      orcidProvider,
    ])
  })
})
