goodsListInit.helpers.test.mjs 1.6 KB
/**
 * @file 众筹同价商品 init helper 单测
 */
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { applySamePriceGoodsToForm } from '../packageCrowdFunding/services/goodsListInit.helpers.js'

describe('goodsListInit.helpers', () => {
  it('applySamePriceGoodsToForm enables multi-goods picker', () => {
    const orderObj = { shopFormList: [{ optionList: [] }] }
    const orderList = [{}, {}, { isMark: false }]
    const data = [
      { goodsId: 'g1', goodsName: 'A;~;B', businessSpecificationId: 'bs1' },
      { goodsId: 'g2', goodsName: 'C', businessSpecificationId: 'bs2' }
    ]

    const result = applySamePriceGoodsToForm({
      data,
      orderObj,
      orderList,
      mapShopmallGoodsId: item => item.goodsId
    })

    assert.equal(result.orderList[2].isMark, true)
    assert.equal(result.orderObj.shopFormList[0].optionList.length, 2)
    assert.equal(result.orderObj.shopFormList[0].optionList[0].goodsName, 'A B')
    assert.equal(result.orderObj.shopFormList[0].optionList[0].shopmallGoodsId, 'g1')
  })

  it('applySamePriceGoodsToForm disables picker for single goods', () => {
    const orderObj = { shopFormList: [{ optionList: [] }] }
    const orderList = [{}, {}, { isMark: true }]
    const data = [{ goodsId: 'g1', goodsName: 'Only', businessSpecificationId: 'bs1' }]

    const result = applySamePriceGoodsToForm({
      data,
      orderObj,
      orderList,
      mapShopmallGoodsId: item => item.businessSpecificationId
    })

    assert.equal(result.orderList[2].isMark, false)
    assert.equal(result.orderObj.shopFormList[0].optionList.length, 0)
  })
})