feat(tip): support dynamic gift products

This commit is contained in:
2026-07-21 13:19:45 +08:00
parent 55cb98ed14
commit 37ff69020b
62 changed files with 2325 additions and 1085 deletions
@@ -13,39 +13,72 @@ describe("PaymentApi", () => {
httpClientMock.mockReset();
});
it("loads public coffee tip plans from the dedicated endpoint", async () => {
it("loads the complete public gift catalog for a character", async () => {
httpClientMock.mockResolvedValue({
success: true,
data: {
characterId: "elio",
categories: [
{
category: "coffee",
name: "Coffee",
productCount: 1,
imageUrl: null,
},
],
plans: [
{
planId: "tip_coffee_usd_19_99",
planName: "Large Coffee",
orderType: "tip",
tipType: "coffee_large",
category: "coffee",
characterId: "elio",
description: "Buy Elio a large coffee",
imageUrl: null,
amountCents: 1999,
currency: "USD",
autoRenew: false,
isFirstRechargeOffer: false,
firstRechargeDiscountPercent: 0,
promotionType: null,
},
],
},
});
const response = await new PaymentApi().getTipPlans();
const response = await new PaymentApi().getGiftProducts("elio");
expect(httpClientMock).toHaveBeenCalledWith("/api/payment/tip-plans");
expect(response).toEqual({
plans: [
{
planId: "tip_coffee_usd_19_99",
planName: "Large Coffee",
amountCents: 1999,
currency: "USD",
},
],
expect(httpClientMock).toHaveBeenCalledWith(
"/api/payment/gift-products",
{ query: { characterId: "elio" } },
);
expect(response.categories[0]?.category).toBe("coffee");
expect(response.plans[0]?.planId).toBe("tip_coffee_usd_19_99");
});
it("posts the paid order id when loading the Tip message", async () => {
httpClientMock.mockResolvedValue({
success: true,
data: {
orderId: "pay_xxx",
characterId: "elio",
planId: "tip_coffee_usd_19_99",
productName: "Large Coffee",
tipCount: 1,
poolIndex: 7,
message: "Thank you for the thoughtful gift.",
},
});
const response = await new PaymentApi().getTipMessage({
orderId: "pay_xxx",
});
expect(httpClientMock).toHaveBeenCalledWith("/api/payment/tip-message", {
method: "POST",
body: { orderId: "pay_xxx" },
});
expect(response.message).toBe("Thank you for the thoughtful gift.");
});
});