| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- import { describe, expect, it } from "vitest";
- import {
- buildEnterpriseCodingPlanCampaignDiscountDetails,
- buildEnterpriseCodingPlanCreateOrderRequest,
- buildEnterpriseCodingPlanEstimateFromPendingOrder,
- buildEnterpriseCodingPlanPaymentContent,
- buildEnterpriseCodingPlanProductList,
- calculateEnterpriseCodingPlanPricingDiscountAmount,
- getEnterpriseCodingPlanFailureStatuses,
- isEnterpriseCodingPlanThirdPartyPaymentRequired,
- isEnterpriseCodingPlanPaymentFailureStatus,
- isEnterpriseCodingPlanPaymentSuccessStatus,
- } from "@/settings/model-provider-section/enterpriseCodingPlanProducts.js";
- describe("Enterprise Coding Plan products", () => {
- it("按后端下发顺序展示企业套餐,并保留 subscribeMode 和采购方式", () => {
- const products = buildEnterpriseCodingPlanProductList([
- {
- productId: "enterprise-lite-monthly",
- tier: "LITE",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "按月采购",
- payAmount: 270,
- },
- {
- productId: "enterprise-pro-yearly",
- tier: "PRO",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "按年采购",
- payAmount: 2700,
- },
- {
- productId: "enterprise-lite-continuous-monthly",
- tier: "LITE",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "连续包月",
- payAmount: 243,
- },
- {
- productId: "enterprise-max-monthly",
- tier: "MAX",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "按月采购",
- payAmount: 900,
- },
- ]);
- expect(products.map((product) => product.productId)).toEqual([
- "enterprise-lite-monthly",
- "enterprise-pro-yearly",
- "enterprise-lite-continuous-monthly",
- "enterprise-max-monthly",
- ]);
- expect(products.map((product) => product.productName)).toEqual([
- "Lite",
- "Pro",
- "Lite",
- "Max",
- ]);
- expect(products.map((product) => product.priceUnit)).toEqual([
- "month",
- "year",
- "month",
- "month",
- ]);
- expect(products.map((product) => product.purchaseMethodName)).toEqual([
- "按月采购",
- "按年采购",
- "连续包月",
- "按月采购",
- ]);
- });
- it("企业卡片价格字段对齐个人套餐:主价用 payAmount,原价用 originalAmount,不把优惠金额当价格", () => {
- const [monthlyProduct, continuousYearlyProduct, oneTimeYearlyProduct] =
- buildEnterpriseCodingPlanProductList([
- {
- productId: "enterprise-pro-monthly",
- tier: "PRO",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "按月采购",
- originalAmount: 720,
- discountAmount: 72,
- payAmount: 648,
- renewAmount: 648,
- },
- {
- productId: "enterprise-pro-continuous-yearly",
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "连续包年",
- originalAmount: 7176,
- discountAmount: 0,
- payAmount: 7176,
- renewAmount: 6458.4,
- },
- {
- productId: "enterprise-pro-yearly",
- tier: "PRO",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "按年采购",
- originalAmount: 7176,
- discountAmount: 0,
- payAmount: 7176,
- renewAmount: 6458.4,
- },
- ]);
- expect(monthlyProduct).toMatchObject({
- originalAmount: 720,
- payAmount: 648,
- renewAmount: 648,
- });
- expect(monthlyProduct.discountAmount).toBeUndefined();
- expect(monthlyProduct.enterpriseProduct.discountAmount).toBe(72);
- expect(continuousYearlyProduct).toMatchObject({
- originalAmount: 7176,
- payAmount: 6458.4,
- priceUnit: "year",
- });
- expect(continuousYearlyProduct.discountAmount).toBeUndefined();
- expect(oneTimeYearlyProduct).toMatchObject({
- originalAmount: 7176,
- payAmount: 6458.4,
- priceUnit: "year",
- });
- expect(oneTimeYearlyProduct.discountAmount).toBeUndefined();
- });
- it("把企业折扣明细转换为支付弹窗活动优惠明细", () => {
- expect(
- buildEnterpriseCodingPlanCampaignDiscountDetails({
- campaignDiscountAmount: 270,
- discountDetails: [
- {
- discountType: "REGULAR_DISCOUNT",
- discountName: "企业套餐九折",
- discountAmount: 270,
- },
- ],
- }),
- ).toEqual([
- {
- campaignName: "企业套餐九折",
- campaignDiscountAmount: 270,
- rewardDetail: "企业套餐九折",
- applyScene: "REGULAR_DISCOUNT",
- },
- ]);
- expect(
- buildEnterpriseCodingPlanCampaignDiscountDetails({
- campaignDiscountAmount: 270,
- discountDetails: [],
- }),
- ).toEqual([
- {
- campaignDiscountAmount: 270,
- },
- ]);
- });
- it("优先使用 pricing 下发的 campaignDiscountDetails 展示企业活动信息,并使用订单总优惠金额", () => {
- expect(
- buildEnterpriseCodingPlanCampaignDiscountDetails({
- campaignDiscountAmount: 216,
- discountDetails: [],
- pricingCampaignDiscountDetails: [
- {
- campaignName: "连续包季 9折",
- campaignDiscountAmount: 72,
- rewardMode: "PERCENT",
- rewardAmount: 10,
- rewardDetail: "连续包月享9折优惠",
- applyScene: "SUBSCRIPTION",
- },
- ],
- }),
- ).toEqual([
- {
- campaignName: "连续包季 9折",
- campaignDiscountAmount: 216,
- rewardMode: "PERCENT",
- rewardAmount: 10,
- rewardDetail: "连续包月享9折优惠",
- applyScene: "SUBSCRIPTION",
- },
- ]);
- });
- it("试算未返回汇总优惠时,用 pricing 顶层 discountAmount 按席位和时长折算", () => {
- const [monthlyOneTimeProduct, yearlyContinuousProduct] =
- buildEnterpriseCodingPlanProductList([
- {
- productId: "enterprise-pro-monthly",
- tier: "PRO",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "按月采购",
- originalAmount: 720,
- discountAmount: 72,
- payAmount: 648,
- renewAmount: 648,
- },
- {
- productId: "enterprise-pro-continuous-yearly",
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "连续包年",
- originalAmount: 7176,
- discountAmount: 0,
- payAmount: 7176,
- renewAmount: 6458.4,
- },
- ]);
- expect(
- calculateEnterpriseCodingPlanPricingDiscountAmount({
- product: monthlyOneTimeProduct,
- maxSeats: 3,
- duration: 2,
- }),
- ).toBe(432);
- expect(
- calculateEnterpriseCodingPlanPricingDiscountAmount({
- product: yearlyContinuousProduct,
- maxSeats: 3,
- duration: 2,
- }),
- ).toBe(2152.8);
- });
- it("多条 pricing 活动按下发金额比例分摊订单总优惠", () => {
- expect(
- buildEnterpriseCodingPlanCampaignDiscountDetails({
- campaignDiscountAmount: 300,
- pricingCampaignDiscountDetails: [
- {
- campaignName: "活动 A",
- campaignDiscountAmount: 20,
- },
- {
- campaignName: "活动 B",
- campaignDiscountAmount: 10,
- },
- ],
- }),
- ).toEqual([
- {
- campaignName: "活动 A",
- campaignDiscountAmount: 200,
- },
- {
- campaignName: "活动 B",
- campaignDiscountAmount: 100,
- },
- ]);
- });
- it("ONE_TIME 下单请求包含 duration,并原样回传试算金额", () => {
- const product = buildEnterpriseCodingPlanProductList([
- {
- productId: "enterprise-lite-monthly",
- tier: "LITE",
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "按月采购",
- payAmount: 270,
- },
- ])[0];
- expect(
- buildEnterpriseCodingPlanCreateOrderRequest({
- product,
- maxSeats: 3,
- duration: 2,
- estimate: {
- totalOriginalAmount: 1620,
- totalPayAmount: 1458,
- thirdPayAmount: 1458,
- },
- }),
- ).toMatchObject({
- productId: "enterprise-lite-monthly",
- maxSeats: 3,
- subscribeMode: "ONE_TIME",
- subscribePeriod: "MONTHLY",
- purchaseType: "PAY",
- duration: 2,
- giveAmount: 0,
- balanceDeductAmount: 0,
- totalOriginalAmount: 1620,
- totalPayAmount: 1458,
- thirdPayAmount: 1458,
- });
- });
- it("支付内容优先使用 payUrl,否则使用 alipayJumpSchema", () => {
- expect(
- buildEnterpriseCodingPlanPaymentContent({
- orderNo: "order-1",
- totalOriginalAmount: 100,
- totalPayAmount: 90,
- thirdPayAmount: 90,
- alipayJumpSchema: "alipays://pay",
- payUrl: "https://pay.example",
- }),
- ).toBe("https://pay.example");
- expect(
- buildEnterpriseCodingPlanPaymentContent({
- orderNo: "order-2",
- totalOriginalAmount: 100,
- totalPayAmount: 90,
- thirdPayAmount: 90,
- alipayJumpSchema: "alipays://pay",
- }),
- ).toBe("alipays://pay");
- });
- it("余额全额抵扣且无支付内容时不要求三方支付", () => {
- expect(
- isEnterpriseCodingPlanThirdPartyPaymentRequired({
- orderNo: "order-free",
- totalOriginalAmount: 100,
- totalPayAmount: 100,
- thirdPayAmount: 0,
- }),
- ).toBe(false);
- expect(
- isEnterpriseCodingPlanThirdPartyPaymentRequired({
- orderNo: "order-pay",
- totalOriginalAmount: 100,
- totalPayAmount: 100,
- thirdPayAmount: 0,
- payUrl: "https://pay.example",
- }),
- ).toBe(true);
- });
- it("把企业待支付订单映射为确认页试算金额", () => {
- expect(
- buildEnterpriseCodingPlanEstimateFromPendingOrder({
- orderNo: "order-pending",
- productId: "enterprise-lite-monthly",
- amount: 2430,
- totalAmount: 2700,
- deductionAmount: 270,
- paymentStatus: "WAIT_PAY",
- createTime: "2026-05-09 14:30:00",
- subscriptionNo: "SUB20260513a1b2c3d4",
- seatCount: 10,
- }),
- ).toEqual({
- totalOriginalAmount: 2700,
- campaignDiscountAmount: 270,
- totalPayAmount: 2430,
- thirdPayAmount: 2430,
- });
- });
- it("识别企业支付成功和失败终态", () => {
- expect(isEnterpriseCodingPlanPaymentSuccessStatus("SUCCESS")).toBe(true);
- expect(isEnterpriseCodingPlanPaymentSuccessStatus("WAIT_PAY")).toBe(false);
- for (const status of getEnterpriseCodingPlanFailureStatuses()) {
- expect(isEnterpriseCodingPlanPaymentFailureStatus(status)).toBe(true);
- }
- });
- });
|