feat(domain): add income calculation with commission support
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
import { calculateOrderIncome } from "@/lib/domain/income"
|
||||
|
||||
describe("calculateOrderIncome", () => {
|
||||
it("calculates percentage commission income", () => {
|
||||
const result = calculateOrderIncome(100, {
|
||||
commissionType: "percentage",
|
||||
commissionValue: 12,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
income: 88,
|
||||
commissionLabel: "扣除12%抽成",
|
||||
})
|
||||
})
|
||||
|
||||
it("calculates fixed commission income", () => {
|
||||
const result = calculateOrderIncome(60, {
|
||||
commissionType: "fixed",
|
||||
commissionValue: 8,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
income: 52,
|
||||
commissionLabel: "扣除¥8固定抽成",
|
||||
})
|
||||
})
|
||||
|
||||
it("keeps full income for independent orders", () => {
|
||||
const result = calculateOrderIncome(90)
|
||||
|
||||
expect(result).toEqual({
|
||||
income: 90,
|
||||
commissionLabel: "独立接单无抽成",
|
||||
})
|
||||
})
|
||||
|
||||
it("does not return negative income for fixed commission", () => {
|
||||
const result = calculateOrderIncome(6, {
|
||||
commissionType: "fixed",
|
||||
commissionValue: 8,
|
||||
})
|
||||
|
||||
expect(result.income).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user