import { describe, it, expect } from 'vitest' import * as fc from 'fast-check' import { recalculateOrderTotal } from '../src/controllers/adminOrder' // Generate an order item with arbitrary unitPrice and quantity const orderItemArb = fc.record({ unitPrice: fc.float({ min: 0, max: 999999, noNaN: true }).map((n) => Math.round(n * 100) / 100), quantity: fc.integer({ min: 1, max: 100 }), }) // Feature: jewelry-mall, Property 8: 订单价格自动重算 // **Validates: Requirements 9.4** describe('Property 8: 订单价格自动重算', () => { it('变更后的订单总价应等于所有订单项的单价乘以数量之和', () => { fc.assert( fc.property( fc.array(orderItemArb, { minLength: 1, maxLength: 20 }), (items) => { const total = recalculateOrderTotal(items) const expected = items.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0) expect(total).toBeCloseTo(expected, 2) } ), { numRuns: 100 } ) }) })