test(chat-machine): add test for ignoring repeated user login during active session
This commit is contained in:
@@ -164,6 +164,30 @@ describe("chatMachine transitions", () => {
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("ignores repeated user login while an authenticated user session is active", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||
await waitFor(actor, (snapshot) =>
|
||||
snapshot.matches({ userSession: "ready" }),
|
||||
);
|
||||
|
||||
actor.send({ type: "ChatSendMessage", content: "keep this message" });
|
||||
await waitFor(
|
||||
actor,
|
||||
(snapshot) => snapshot.context.messages.length === 1,
|
||||
);
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "another-token" });
|
||||
|
||||
expect(actor.getSnapshot().matches({ userSession: "ready" })).toBe(true);
|
||||
expect(actor.getSnapshot().context.messages).toMatchObject([
|
||||
{ content: "keep this message", isFromAI: false },
|
||||
]);
|
||||
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("allows multiple messages to be queued without leaving ready state", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user