fix : not allow to delete message while ticket closed
This commit is contained in:
@@ -38,7 +38,7 @@ describe("commission message deletion", () => {
|
||||
beforeEach(() => {
|
||||
process.env.BETTER_AUTH_URL = "https://guide.sudloh.com";
|
||||
vi.clearAllMocks();
|
||||
authorizeTicket.mockResolvedValue({ ticket: { userId: ownerId }, user: { id: ownerId } });
|
||||
authorizeTicket.mockResolvedValue({ ticket: { userId: ownerId, status: "open" }, user: { id: ownerId } });
|
||||
deleteWhere.mockImplementation(() => ({ returning: deleteReturning }));
|
||||
deleteReturning.mockResolvedValue([{ imageObjectKey: "commission/messages/image-1" }]);
|
||||
updateWhere.mockResolvedValue(undefined);
|
||||
@@ -66,6 +66,15 @@ describe("commission message deletion", () => {
|
||||
expect(notifyCommission).toHaveBeenCalledWith(ticketId, ownerId);
|
||||
});
|
||||
|
||||
it("rejects deletion when the ticket is closed", async () => {
|
||||
authorizeTicket.mockResolvedValue({ ticket: { userId: ownerId, status: "closed" }, user: { id: ownerId } });
|
||||
const response = await DELETE(deletionRequest(), context());
|
||||
expect(response.status).toBe(409);
|
||||
expect(tx.delete).not.toHaveBeenCalled();
|
||||
expect(deleteObject).not.toHaveBeenCalled();
|
||||
expect(notifyCommission).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("leaves storage and notifications untouched when no owned message exists", async () => {
|
||||
deleteReturning.mockResolvedValue([]);
|
||||
const response = await DELETE(deletionRequest(), context());
|
||||
|
||||
Reference in New Issue
Block a user