import { describe, it, expect } from 'vitest'
import { getSessionMaxAgeDays } from '../../server/utils/constants.js'
import { withTemporaryEnv } from '../helpers/env.js'

describe('session', () => {
  it.each([
    [{ SESSION_MAX_AGE_DAYS: undefined }, 7],
    [{ SESSION_MAX_AGE_DAYS: 'invalid' }, 7],
    [{ SESSION_MAX_AGE_DAYS: '0' }, 1],
    [{ SESSION_MAX_AGE_DAYS: '400' }, 365],
    [{ SESSION_MAX_AGE_DAYS: '14' }, 14],
  ])('returns correct days for SESSION_MAX_AGE_DAYS=%s', (env, expected) => {
    withTemporaryEnv(env, () => {
      expect(getSessionMaxAgeDays()).toBe(expected)
    })
  })
})
