import { describe, expect, it } from 'vitest'
import { effectivePrice } from './pricing.js'

describe('effectivePrice', () => {
  const base = { price: 20, specialPrice: 15, specialFrom: null, specialTo: null }

  it('applies an open-ended special price that is lower', () => {
    expect(effectivePrice(base, '2026-10-08')).toMatchObject({ specialActive: true, effectivePrice: 15 })
  })
  it('respects the inclusive date window', () => {
    expect(effectivePrice({ ...base, specialFrom: '2026-10-09' }, '2026-10-08').effectivePrice).toBe(20)
    expect(effectivePrice({ ...base, specialTo: '2026-10-08 00:00:00' }, '2026-10-08').effectivePrice).toBe(15)
    expect(effectivePrice({ ...base, specialTo: '2026-10-07' }, '2026-10-08').effectivePrice).toBe(20)
  })
  it('ignores a special price that is not lower', () => {
    expect(effectivePrice({ ...base, specialPrice: 25 }, '2026-10-08')).toMatchObject({ specialActive: false, effectivePrice: 20 })
  })
})
