goodsListInit.helpers.test.mjs
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @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)
})
})