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

import {
  resolveKuaishouSendCodeShopName,
  resolveKuaishouSendCodeWorkOrderData,
} from './sync-work-orders-from-send-code.js'

test('快手发码工单优先使用 ext.skuNick 与 payment', () => {
  const result = resolveKuaishouSendCodeWorkOrderData(
    {
      sellerId: '141242642',
      itemId: '25873410102642',
      itemTitle: '和平精英指挥官密钥秘钥隐藏款密钥暮色之下灰烬之翎珍宝礼盒礼卡',
      skuId: '185469355612642',
      num: 1,
      paymentFen: 1400,
      rawParams: {
        ext: '{"skuNick":"指挥官密钥1个","payment":1400}',
      },
    },
    [
      {
        sellerId: '141242642',
        shopId: '141242642',
        shopName: '授权店铺名',
        customShopName: '快手密钥店',
      },
    ],
  )

  assert.deepEqual(result, {
    sellerId: '141242642',
    shopName: '快手密钥店',
    itemId: '25873410102642',
    itemTitle: '和平精英指挥官密钥秘钥隐藏款密钥暮色之下灰烬之翎珍宝礼盒礼卡',
    skuId: '185469355612642',
    relItemId: '',
    relSkuId: '',
    skuNick: '指挥官密钥1个',
    quantity: 1,
    paymentFen: 1400,
  })
})

test('未配置授权店铺名时保留 sellerId 兜底名称', () => {
  assert.equal(resolveKuaishouSendCodeShopName('141242642'), '快手店铺-141242642')
})
