feat(characters): support character-scoped conversations
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createActor, waitFor } from "xstate";
|
||||
|
||||
import { createTestChatMachine } from "./chat-machine.test-utils";
|
||||
import {
|
||||
createTestChatMachine,
|
||||
TEST_CHAT_MACHINE_INPUT,
|
||||
} from "./chat-machine.test-utils";
|
||||
|
||||
describe("chat session flow", () => {
|
||||
it("initializes the conversation from the supplied character", () => {
|
||||
const actor = createActor(createTestChatMachine(), {
|
||||
input: { characterId: "character_aria" },
|
||||
}).start();
|
||||
|
||||
expect(actor.getSnapshot().context.characterId).toBe("character_aria");
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("keeps guest logout disabled and supports user to guest transition", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
const actor = createActor(createTestChatMachine(), {
|
||||
input: TEST_CHAT_MACHINE_INPUT,
|
||||
}).start();
|
||||
|
||||
actor.send({ type: "ChatGuestLogin" });
|
||||
await waitFor(actor, (snapshot) =>
|
||||
@@ -29,7 +43,9 @@ describe("chat session flow", () => {
|
||||
});
|
||||
|
||||
it("allows explicit logout from user session", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
const actor = createActor(createTestChatMachine(), {
|
||||
input: TEST_CHAT_MACHINE_INPUT,
|
||||
}).start();
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||
await waitFor(actor, (snapshot) =>
|
||||
@@ -54,6 +70,7 @@ describe("chat session flow", () => {
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ input: TEST_CHAT_MACHINE_INPUT },
|
||||
).start();
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||
@@ -82,7 +99,9 @@ describe("chat session flow", () => {
|
||||
});
|
||||
|
||||
it("switches to guest session when guest login arrives during user session", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
const actor = createActor(createTestChatMachine(), {
|
||||
input: TEST_CHAT_MACHINE_INPUT,
|
||||
}).start();
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||
await waitFor(actor, (snapshot) =>
|
||||
@@ -98,7 +117,9 @@ describe("chat session flow", () => {
|
||||
});
|
||||
|
||||
it("ignores repeated user login while an authenticated user session is active", async () => {
|
||||
const actor = createActor(createTestChatMachine()).start();
|
||||
const actor = createActor(createTestChatMachine(), {
|
||||
input: TEST_CHAT_MACHINE_INPUT,
|
||||
}).start();
|
||||
|
||||
actor.send({ type: "ChatUserLogin", token: "token" });
|
||||
await waitFor(actor, (snapshot) =>
|
||||
|
||||
Reference in New Issue
Block a user