ca4bef959f
Adjust all entity types to match actual backend response shapes. String-typed numeric fields (Shop.rating, Shop.commissionValue, WalletTransaction.amount) now correctly typed as strings. Post.linkedOrderId changed from SnowflakeId to number (backend int64). Removed fields absent from backend: Order consumer/player/shopName, Review fromUserAvatar/toUserId, Dispute initiatorId/initiatorName, Post authorRole/quotedPostId, Comment postId, ChatSession readonly/lastMessageAt, ChatMessage senderName/senderAvatar. Added Player.gender field.
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { calculateOrderIncome } from "@/lib/domain/income"
|
|
import { describe, expect, it } from "vitest"
|
|
|
|
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)
|
|
})
|
|
})
|