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

import { normalizeKuaishouFeifeiSourceConfig } from './source-config-service.js'

test('normalizeKuaishouFeifeiSourceConfig keeps valid product rules and drops invalid ones', () => {
  const config = normalizeKuaishouFeifeiSourceConfig({
    enabled: true,
    baseUrl: ' https://feifei.example.com/ ',
    appKey: ' app-key ',
    appSecret: ' secret ',
    timeoutMs: 0,
    productRules: [
      {
        productName: '套装-Alan Walker',
        productCode: 'FF-1001',
        skuName: 'Alan Walker 套装',
        notes: '测试规则',
      },
      {
        productName: '套装-Alan Walker',
        productCode: 'FF-1002',
      },
      {
        productName: '缺少编码',
        productCode: '',
      },
    ],
  })

  assert.equal(config.enabled, true)
  assert.equal(config.baseUrl, 'https://feifei.example.com/')
  assert.equal(config.appKey, 'app-key')
  assert.equal(config.appSecret, 'secret')
  assert.equal(config.timeoutMs, 10000)
  assert.equal(config.productRules.length, 1)
  assert.equal(config.productRules[0].productName, '套装-Alan Walker')
  assert.equal(config.productRules[0].productCode, 'FF-1002')
  assert.equal(config.productRules[0].normalizedProductName, '套装 alan walker')
})
