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

import { buildOpen91SourceEvent } from './order-service.js'

test('buildOpen91SourceEvent maps 91 productNo into source item identities', () => {
  const event = buildOpen91SourceEvent({
    orderNo: 'P91KS202605130001',
    productNo: 'KS-CLOUD-SKU-001',
    buyNum: 2,
    maxAmount: '0.01',
    timestamp: 1778670308,
    version: '1.0',
    sign: 'SIGN',
  }, {
    shopId: '91kaquan',
    shopName: '91卡券',
  })

  assert.equal(event.provider, '91kaquan')
  assert.equal(event.platform, 'kuaishou')
  assert.equal(event.shopId, '91kaquan')
  assert.equal(event.platformOrderId, 'P91KS202605130001')
  assert.equal(event.payStatus, 'paid')
  assert.equal(event.items.length, 1)
  assert.equal(event.items[0].externalItemId, 'KS-CLOUD-SKU-001')
  assert.equal(event.items[0].externalSkuCode, 'KS-CLOUD-SKU-001')
  assert.equal(event.items[0].externalSkuName, 'KS-CLOUD-SKU-001')
  assert.equal(event.items[0].quantity, 2)
  assert.equal(event.items[0].snapshot.productNo, 'KS-CLOUD-SKU-001')
})
