Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithcheese committed Jul 30, 2024
1 parent 419f847 commit 8944d9a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/routes/(app)/$data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -101,8 +101,6 @@ describe("(app)/$data", () => {
prompt: "",
createdAt: expect.any(String),
});

expect(vi.mocked(invalidate)).toHaveBeenCalledWith("view:chats");
});
});

Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/routes/(app)/$data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/(app)/chat/[id]/$data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 8944d9a

Please sign in to comment.