selectOrderCatalogPreprocess.test.mjs 1.95 KB
import { register } from 'node:module'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'

register(
  '../../../../tests/work-order-migration/shims/resolve-tilde-loader.mjs',
  import.meta.url
)

const { preprocessSelectOrderCatalogItem } = await import(
  '../services/selectOrderCatalogPreprocess.js'
)
const { SELECT_ORDER_GOODS_FLAG } = await import(
  '../services/selectOrderCatalogClassification.js'
)

describe('selectOrderCatalogPreprocess', () => {
  it('IT-WO-PRE-001: single goods seeds price fields', () => {
    const item = {
      goodsFlag: SELECT_ORDER_GOODS_FLAG.SINGLE,
      goods: { sellPrice: 100, merchantGoodsId: 1, position: '前挡' }
    }
    preprocessSelectOrderCatalogItem(item)
    assert.equal(item.goods.price, 100)
    assert.equal(item.goods.goodsId, 1)
    assert.equal(item.goods.positionStr, '前挡')
  })

  it('IT-WO-PRE-002: multi-spec builds specificationSelectValueList', () => {
    const item = {
      goodsFlag: SELECT_ORDER_GOODS_FLAG.MULTI_SPEC,
      multipleSpecificationsGoods: {
        goods: { sellPrice: 50 },
        specificationList: [
          {
            specificationValueList: [
              { show: true, specificationValue: 'L' },
              { show: false, specificationValue: 'M' }
            ]
          }
        ]
      }
    }
    preprocessSelectOrderCatalogItem(item)
    assert.deepEqual(
      item.multipleSpecificationsGoods.specificationList[0]
        .specificationSelectValueList,
      ['L']
    )
  })

  it('IT-WO-PRE-003: package preprocesses child goods', () => {
    const item = {
      goodsFlag: SELECT_ORDER_GOODS_FLAG.PACKAGE,
      packageGoods: {
        goodsList: [{ sellPrice: 10, merchantGoodsId: 2 }]
      }
    }
    preprocessSelectOrderCatalogItem(item)
    assert.equal(item.packageGoods.goodsList[0].merchantGoodsId, 2)
  })

  it('IT-WO-PRE-004: null item no-op', () => {
    assert.doesNotThrow(() => preprocessSelectOrderCatalogItem(null))
  })
})