import { describe, expect, it } from 'vitest'
import { isIndexable, robotsValue } from './gate.js'

describe('@platform-modules/seo/gate', () => {
  it('isIndexable maps to robotsValue both ways', () => {
    const indexable = isIndexable(
      { indexingEnabled: true },
      { published: true },
      { published: true },
    )
    expect(indexable).toBe(true)
    expect(robotsValue(indexable)).toBe('index,follow')

    const blocked = isIndexable(
      { indexingEnabled: false },
      { published: true },
    )
    expect(blocked).toBe(false)
    expect(robotsValue(blocked)).toBe('noindex,nofollow')
  })

  it('thread noindex blocks indexing when tenant and node are otherwise indexable', () => {
    const blocked = isIndexable(
      { indexingEnabled: true },
      { published: true },
      { published: true, noindex: true },
    )
    expect(robotsValue(blocked)).toBe('noindex,nofollow')
  })

  it('node-level rejection: unpublished or noindex node blocks indexing', () => {
    expect(isIndexable({ indexingEnabled: true }, { published: false })).toBe(false)
    expect(isIndexable({ indexingEnabled: true }, { published: true, noindex: true })).toBe(false)
  })
})
