fix(chat): suppress paywall for missing unlock

This commit is contained in:
2026-07-15 14:44:12 +08:00
parent 58ca40a728
commit 684ae4bf5d
2 changed files with 89 additions and 24 deletions
@@ -490,6 +490,68 @@ describe("chat unlock flow", () => {
actor.stop();
});
it("does not request payment when the unlock target is not found", async () => {
const actor = createActor(
createTestChatMachine({
historyMessages: [
{
id: "msg-missing",
content: "",
isFromAI: true,
date: "2026-06-29",
locked: true,
lockReason: "private_message",
privateMessageHint: "A private message is waiting.",
},
],
unlockMessageOutput: {
messageId: "msg-missing",
response: makeUnlockPrivateResponse({
unlocked: false,
content: "",
reason: "not_found",
creditBalance: 3,
creditsCharged: 0,
requiredCredits: 0,
shortfallCredits: 0,
}),
},
}),
).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>
snapshot.matches({ userSession: "ready" }),
);
actor.send({
type: "ChatUnlockMessageRequested",
messageId: "msg-missing",
kind: "private",
});
await waitFor(
actor,
(snapshot) => snapshot.context.unlockMessageError === "not_found",
);
expect(actor.getSnapshot().context).toMatchObject({
isUnlockingMessage: false,
unlockingMessageId: null,
unlockMessageError: "not_found",
unlockPaywallRequest: null,
});
expect(actor.getSnapshot().context.messages).toMatchObject([
{
id: "msg-missing",
locked: true,
lockReason: "private_message",
},
]);
actor.stop();
});
it("clears the insufficient credits prompt after payment succeeds", async () => {
const actor = createActor(createTestChatMachine()).start();