diff --git a/src/routes/(app)/$data.test.ts b/src/routes/(app)/$data.test.ts index 265a635..8d4ef90 100644 --- a/src/routes/(app)/$data.test.ts +++ b/src/routes/(app)/$data.test.ts @@ -87,7 +87,7 @@ describe("(app)/$data", () => { describe("newChat", () => { it("should create a new chat", async () => { - vi.mocked(nanoid).mockReturnValueOnce("newChatId"); + vi.mocked(nanoid).mockReturnValueOnce("newChatId").mockReturnValueOnce("newRevisionId"); const newChatId = await newChat(); expect(newChatId).toBe("newChatId"); @@ -101,8 +101,6 @@ describe("(app)/$data", () => { prompt: "", createdAt: expect.any(String), }); - - expect(vi.mocked(invalidate)).toHaveBeenCalledWith("view:chats"); }); }); @@ -130,7 +128,7 @@ describe("(app)/$data", () => { }); it("should create a new chat if no chats remain", async () => { - vi.mocked(nanoid).mockReturnValueOnce("newChatId"); + vi.mocked(nanoid).mockReturnValueOnce("newChatId").mockReturnValueOnce("newRevisionId"); await db.delete(schema.chatTable); const nextChatId = await removeChat("non-existent-chat"); diff --git a/src/routes/(app)/$data.ts b/src/routes/(app)/$data.ts index d06adb1..89dee88 100644 --- a/src/routes/(app)/$data.ts +++ b/src/routes/(app)/$data.ts @@ -5,20 +5,20 @@ import { nanoid } from "nanoid"; import { invalidate } from "$app/navigation"; export async function newChat() { - const id = nanoid(10); + const chatId = nanoid(10); await useDb().transaction(async (tx) => { await tx.insert(chatTable).values({ - id: id, + id: chatId, name: "Untitled", prompt: "", }); await tx.insert(revisionTable).values({ id: nanoid(10), version: 1, - chatId: id, + chatId: chatId, }); }); - return id; + return chatId; } export async function removeChat(chatId: string) { diff --git a/src/routes/(app)/chat/[id]/$data.test.ts b/src/routes/(app)/chat/[id]/$data.test.ts index f9b6bb1..969fddf 100644 --- a/src/routes/(app)/chat/[id]/$data.test.ts +++ b/src/routes/(app)/chat/[id]/$data.test.ts @@ -214,9 +214,9 @@ describe("appendMessage", () => { id: "new-message", role: "user", content: "New message content", - revisionId: "revision2", + attachments: [], }; - await appendMessages(message, []); + await appendMessages("revision2", [message]); const messages = await db.query.messageTable.findMany({ where: eq(schema.messageTable.revisionId, "revision2"),