import test from 'node:test'
import assert from 'node:assert/strict'

import { normalizeDateTimeString } from './admin-query-utils.js'

test('normalizeDateTimeString 保留纯日期并按天过滤', () => {
  assert.equal(normalizeDateTimeString('2026-08-22'), '2026-08-22')
})

test('normalizeDateTimeString 接受到分钟并补零秒', () => {
  assert.equal(normalizeDateTimeString('2026-08-22 10:30'), '2026-08-22 10:30:00')
})

test('normalizeDateTimeString 接受到秒', () => {
  assert.equal(normalizeDateTimeString('2026-08-22 10:30:59'), '2026-08-22 10:30:59')
})

test('normalizeDateTimeString 拒绝非法输入', () => {
  assert.equal(normalizeDateTimeString(''), '')
  assert.equal(normalizeDateTimeString(undefined), '')
  assert.equal(normalizeDateTimeString('2026-8-22'), '')
  assert.equal(normalizeDateTimeString('2026-08-22T10:30:00'), '')
  assert.equal(normalizeDateTimeString('2026-08-22 24:00'), '')
  assert.equal(normalizeDateTimeString('2026-08-22 10:60'), '')
  assert.equal(normalizeDateTimeString('2026-08-22 10:30:60'), '')
  assert.equal(normalizeDateTimeString('2026-02-31 10:30'), '')
})
