This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -2,45 +2,45 @@ import { describe, expect, it } from "vitest";
|
||||
import { createOwnedTicketReply } from "@/lib/services/ticket-replies";
|
||||
|
||||
describe("createOwnedTicketReply", () => {
|
||||
it("does not create a reply for a ticket owned by another user", async () => {
|
||||
let created = false;
|
||||
const db = {
|
||||
findTicket: async () => ({ id: 5n, userId: 7 }),
|
||||
createReply: async () => {
|
||||
created = true;
|
||||
throw new Error("must not run");
|
||||
},
|
||||
touchTicket: async () => undefined,
|
||||
};
|
||||
it("does not create a reply for a ticket owned by another user", async () => {
|
||||
let created = false;
|
||||
const db = {
|
||||
findTicket: async () => ({ id: 5n, userId: 7 }),
|
||||
createReply: async () => {
|
||||
created = true;
|
||||
throw new Error("must not run");
|
||||
},
|
||||
touchTicket: async () => undefined,
|
||||
};
|
||||
|
||||
await expect(
|
||||
createOwnedTicketReply(db, { ticketId: 5n, userId: 99, content: "Help" }),
|
||||
).resolves.toBeNull();
|
||||
expect(created).toBe(false);
|
||||
});
|
||||
await expect(
|
||||
createOwnedTicketReply(db, { ticketId: 5n, userId: 99, content: "Help" }),
|
||||
).resolves.toBeNull();
|
||||
expect(created).toBe(false);
|
||||
});
|
||||
|
||||
it("creates the reply and updates ticket activity as one operation", async () => {
|
||||
let touchedAt: Date | undefined;
|
||||
const db = {
|
||||
findTicket: async () => ({ id: 5n, userId: 99 }),
|
||||
createReply: async (data: { createdAt: Date }) => ({
|
||||
id: 8n,
|
||||
userId: 99,
|
||||
content: "Help",
|
||||
createdAt: data.createdAt,
|
||||
}),
|
||||
touchTicket: async (_ticketId: bigint, updatedAt: Date) => {
|
||||
touchedAt = updatedAt;
|
||||
},
|
||||
};
|
||||
it("creates the reply and updates ticket activity as one operation", async () => {
|
||||
let touchedAt: Date | undefined;
|
||||
const db = {
|
||||
findTicket: async () => ({ id: 5n, userId: 99 }),
|
||||
createReply: async (data: { createdAt: Date }) => ({
|
||||
id: 8n,
|
||||
userId: 99,
|
||||
content: "Help",
|
||||
createdAt: data.createdAt,
|
||||
}),
|
||||
touchTicket: async (_ticketId: bigint, updatedAt: Date) => {
|
||||
touchedAt = updatedAt;
|
||||
},
|
||||
};
|
||||
|
||||
const reply = await createOwnedTicketReply(db, {
|
||||
ticketId: 5n,
|
||||
userId: 99,
|
||||
content: "Help",
|
||||
});
|
||||
const reply = await createOwnedTicketReply(db, {
|
||||
ticketId: 5n,
|
||||
userId: 99,
|
||||
content: "Help",
|
||||
});
|
||||
|
||||
expect(reply).toMatchObject({ id: 8n, userId: 99, content: "Help" });
|
||||
expect(touchedAt).toBe(reply?.createdAt);
|
||||
});
|
||||
expect(reply).toMatchObject({ id: 8n, userId: 99, content: "Help" });
|
||||
expect(touchedAt).toBe(reply?.createdAt);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user