fix(chat): clear limit prompt after payment

This commit is contained in:
2026-06-29 11:27:39 +08:00
parent 2207301ccb
commit 934b92502b
2 changed files with 59 additions and 5 deletions
@@ -354,4 +354,52 @@ describe("chatMachine transitions", () => {
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();
});
});