35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
const { toOrderCards, toOrderDetail } = require('./orderPresenter')
|
|
|
|
describe('toOrderCards', () => {
|
|
test('normalizes mixed orders for list display', () => {
|
|
const cards = toOrderCards({
|
|
goodsOrders: [{ id: 1, orderNo: 'GO00000001', payableAmountCent: 1590, status: 'PENDING_DELIVERY' }],
|
|
expressOrders: [{ id: 2, orderNo: 'EO00000001', expressCompany: 'SF', pickupCode: 'A1', feeCent: 400, status: 'PENDING_PICKUP' }],
|
|
groupBuyOrders: [{ id: 3, orderNo: 'GB00000001', groupBuyTitle: 'Today eggs', amountCent: 5980, status: 'PENDING_CONFIRM' }]
|
|
})
|
|
|
|
expect(cards).toEqual([
|
|
expect.objectContaining({ id: 1, type: 'goods', title: 'GO00000001', amountText: '¥15.90', statusText: '待配送' }),
|
|
expect.objectContaining({ id: 2, type: 'express', title: 'SF A1', amountText: '¥4.00', statusText: '待自提' }),
|
|
expect.objectContaining({ id: 3, type: 'group', title: 'Today eggs', amountText: '¥59.80', statusText: '待确认' })
|
|
])
|
|
})
|
|
|
|
test('normalizes an order detail for display', () => {
|
|
expect(toOrderDetail('goods', {
|
|
id: 1,
|
|
orderNo: 'GO00000001',
|
|
totalAmountCent: 1290,
|
|
deliveryFeeCent: 300,
|
|
payableAmountCent: 1590,
|
|
status: 'PENDING_DELIVERY'
|
|
})).toEqual(expect.objectContaining({
|
|
orderNo: 'GO00000001',
|
|
statusText: '待配送',
|
|
totalAmountText: '¥12.90',
|
|
deliveryFeeText: '¥3.00',
|
|
payableAmountText: '¥15.90'
|
|
}))
|
|
})
|
|
})
|