quotationPricing.workflow.test.mjs
2.64 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
buildPricingPayload,
requestQuotationPrice,
validateRecordedPriceLimit
} from '../pages/carQuotation/services/quotationPricing.workflow.js'
describe('quotationPricing.workflow', () => {
it('accepts only numeric or string zero success codes', async () => {
for (const code of [0, '0']) {
const result = await requestQuotationPrice(
{ goodsId: 12 },
{ priceCounter: async () => ({ code, data: { quotedPriceUpdate: 9900 } }) }
)
assert.equal(result.status, 'success')
assert.equal(result.data.quotedPriceUpdate, 9900)
}
for (const code of [1, '1', true, undefined]) {
const result = await requestQuotationPrice(
{ goodsId: 12 },
{ priceCounter: async () => ({ code, message: '不可报价' }) }
)
assert.deepEqual(result, {
status: 'business-error',
data: undefined,
message: '不可报价',
code
})
}
})
it('preserves payload identity and propagates reject', async () => {
const payload = { goodsId: 12, owner: { owner: '李四' } }
let received
await assert.rejects(
requestQuotationPrice(payload, {
priceCounter: async value => {
received = value
throw new Error('counter unavailable')
}
}),
/counter unavailable/
)
assert.equal(received, payload)
})
it('builds a new payload without mutating owner or quotation', () => {
const owner = { owner: '王五', buyCarTime: '2026-01-01', salesType: '售后' }
const quotation = {
owner: { stale: true },
quotedPriceUpdate: 100,
insureList: [{ type: 3, appreciation: 1 }]
}
const result = buildPricingPayload({
owner,
quotation,
goods: { id: 8, goodsName: '延保', appreciation: 8 }
})
assert.deepEqual(result.owner, { owner: '王五', salesType: 1 })
assert.equal(result.goodsId, 8)
assert.equal(result.goodsName, '延保')
assert.equal(result.quotedPriceUpdate, undefined)
assert.deepEqual(owner, {
owner: '王五',
buyCarTime: '2026-01-01',
salesType: '售后'
})
assert.deepEqual(quotation.insureList, [{ type: 3, appreciation: 1 }])
})
it('compares recorded totals and minimum equity prices as integer cents', () => {
assert.deepEqual(validateRecordedPriceLimit(100, 100), { ok: true })
assert.deepEqual(validateRecordedPriceLimit('101', 100), {
ok: false,
reason: 'above-recorded-total'
})
assert.deepEqual(validateRecordedPriceLimit('1.01', 100), {
ok: false,
reason: 'invalid'
})
})
})