fix(chat): clear limit prompt after payment
This commit is contained in:
@@ -354,4 +354,52 @@ describe("chatMachine transitions", () => {
|
|||||||
|
|
||||||
actor.stop();
|
actor.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("clears the daily limit prompt after payment succeeds", async () => {
|
||||||
|
const actor = createActor(createTestChatMachine()).start();
|
||||||
|
|
||||||
|
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||||
|
await waitFor(actor, (snapshot) =>
|
||||||
|
snapshot.matches({ userSession: "ready" }),
|
||||||
|
);
|
||||||
|
|
||||||
|
actor.send({
|
||||||
|
type: "ChatQueuedHttpDone",
|
||||||
|
output: {
|
||||||
|
response: ChatSendResponse.from({
|
||||||
|
reply: "",
|
||||||
|
audioUrl: "",
|
||||||
|
messageId: "",
|
||||||
|
isGuest: false,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
image: { type: null, url: null },
|
||||||
|
lockDetail: {
|
||||||
|
locked: true,
|
||||||
|
showContent: false,
|
||||||
|
showUpgrade: true,
|
||||||
|
reason: "daily_limit",
|
||||||
|
hint: "Free message limit reached.",
|
||||||
|
detail: {
|
||||||
|
type: "daily_msg_limit",
|
||||||
|
usedToday: 3,
|
||||||
|
limit: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
reply: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(actor.getSnapshot().context.upgradePromptVisible).toBe(true);
|
||||||
|
expect(actor.getSnapshot().context.upgradeReason).toBe("daily_limit");
|
||||||
|
|
||||||
|
actor.send({ type: "ChatPaymentSucceeded" });
|
||||||
|
|
||||||
|
expect(actor.getSnapshot().context.upgradePromptVisible).toBe(false);
|
||||||
|
expect(actor.getSnapshot().context.upgradeReason).toBeNull();
|
||||||
|
expect(actor.getSnapshot().context.upgradeHint).toBeNull();
|
||||||
|
expect(actor.getSnapshot().context.upgradeDetail).toBeNull();
|
||||||
|
|
||||||
|
actor.stop();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -218,6 +218,13 @@ export const chatMachine = setup({
|
|||||||
return applyHttpSendOutput(context, event.output);
|
return applyHttpSendOutput(context, event.output);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
clearUpgradePrompt: assign(() => ({
|
||||||
|
upgradePromptVisible: false,
|
||||||
|
upgradeReason: null,
|
||||||
|
upgradeHint: null,
|
||||||
|
upgradeDetail: null,
|
||||||
|
})),
|
||||||
|
|
||||||
markPaymentUnlockPending: assign(() => ({
|
markPaymentUnlockPending: assign(() => ({
|
||||||
paymentUnlockPending: true,
|
paymentUnlockPending: true,
|
||||||
unlockHistoryError: null,
|
unlockHistoryError: null,
|
||||||
@@ -290,7 +297,6 @@ export const chatMachine = setup({
|
|||||||
initial: "initializing",
|
initial: "initializing",
|
||||||
states: {
|
states: {
|
||||||
initializing: {
|
initializing: {
|
||||||
// 本地游客额度逻辑已停用:只等待历史加载完成。
|
|
||||||
always: [
|
always: [
|
||||||
{
|
{
|
||||||
target: "ready",
|
target: "ready",
|
||||||
@@ -376,21 +382,21 @@ export const chatMachine = setup({
|
|||||||
guard: ({ context }) =>
|
guard: ({ context }) =>
|
||||||
context.historyLoaded && shouldAutoUnlockHistory(context.messages),
|
context.historyLoaded && shouldAutoUnlockHistory(context.messages),
|
||||||
target: ".unlockingHistory",
|
target: ".unlockingHistory",
|
||||||
actions: "markUnlockHistoryStarted",
|
actions: ["clearUpgradePrompt", "markUnlockHistoryStarted"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
guard: ({ context }) =>
|
guard: ({ context }) =>
|
||||||
context.historyLoaded &&
|
context.historyLoaded &&
|
||||||
shouldPromptUnlockHistory(context.messages),
|
shouldPromptUnlockHistory(context.messages),
|
||||||
actions: "showUnlockHistoryPrompt",
|
actions: ["clearUpgradePrompt", "showUnlockHistoryPrompt"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
guard: ({ context }) => !context.historyLoaded,
|
guard: ({ context }) => !context.historyLoaded,
|
||||||
actions: "markPaymentUnlockPending",
|
actions: ["clearUpgradePrompt", "markPaymentUnlockPending"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
guard: ({ context }) => context.historyLoaded,
|
guard: ({ context }) => context.historyLoaded,
|
||||||
actions: "dismissUnlockHistoryPrompt",
|
actions: ["clearUpgradePrompt", "dismissUnlockHistoryPrompt"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
ChatUnlockHistoryConfirmed: {
|
ChatUnlockHistoryConfirmed: {
|
||||||
|
|||||||
Reference in New Issue
Block a user