feat : update i guess
CI / Verify (push) Failing after 1m4s
CI / Build immutable images and deploy (push) Skipped

This commit is contained in:
2026-10-03 15:47:47 +07:00 Unverified
parent f5cfe0a22e
commit 95c45841e7
15 changed files with 4297 additions and 174 deletions
@@ -8,12 +8,17 @@ const selectWhere = vi.fn((condition: SQL) => { void condition; return { limit:
const insertReturning = vi.fn();
const insertValues = vi.fn(() => ({ returning: insertReturning }));
const updateWhere = vi.fn();
const writeObject = vi.fn();
const deleteObject = vi.fn();
const inspectImage = vi.fn();
const tx = { insert: vi.fn(() => ({ values: insertValues })), update: vi.fn(() => ({ set: () => ({ where: updateWhere }) })) };
const notifyCommission = vi.fn();
vi.mock("@/lib/commission/tickets", () => ({ authorizeTicket }));
vi.mock("@/lib/commission/server", () => ({ notifyCommission }));
vi.mock("@/lib/commission/push", () => ({ sendCommissionMessagePush: vi.fn() }));
vi.mock("@/lib/media/storage", () => ({ getMediaStorage: async () => ({ write: writeObject, delete: deleteObject }) }));
vi.mock("@/lib/media/inspect", () => ({ inspectImage }));
vi.mock("@/lib/security/rate-limit", () => ({ limitRequest: async () => undefined }));
vi.mock("next/server", () => ({ after: vi.fn() }));
vi.mock("@/db", () => ({ getDb: () => ({
@@ -47,6 +52,9 @@ describe("commission message replies", () => {
user: { id: "user-1", name: "User" } });
selectLimit.mockResolvedValue([{ id: parentId }]);
insertReturning.mockResolvedValue([{ id: messageId }]);
writeObject.mockResolvedValue(undefined);
deleteObject.mockResolvedValue(undefined);
inspectImage.mockResolvedValue(undefined);
});
it("accepts a reply only after looking up its parent in the same ticket", async () => {
@@ -65,4 +73,50 @@ describe("commission message replies", () => {
expect(response.status).toBe(404);
expect(insertValues).not.toHaveBeenCalled();
});
it("stores seven images in one message", async () => {
const body = new FormData();
for (let index = 0; index < 7; index++)
body.append("image", new File(["image"], `${index}.png`, { type: "image/png" }));
const response = await POST(new Request(`https://guide.sudloh.com/api/commission/tickets/${ticketId}/messages`, {
method: "POST", headers: { Origin: "https://guide.sudloh.com" }, body,
}), context());
expect(response.status).toBe(201);
expect(writeObject).toHaveBeenCalledTimes(7);
expect(insertValues).toHaveBeenCalledWith(expect.objectContaining({
imageObjectKeys: writeObject.mock.calls.map(([key]) => key),
}));
});
it("rejects more than ten images before uploading", async () => {
const body = new FormData();
for (let index = 0; index < 11; index++)
body.append("image", new File(["image"], `${index}.png`, { type: "image/png" }));
const response = await POST(new Request(`https://guide.sudloh.com/api/commission/tickets/${ticketId}/messages`, {
method: "POST", headers: { Origin: "https://guide.sudloh.com" }, body,
}), context());
expect(response.status).toBe(400);
expect(writeObject).not.toHaveBeenCalled();
});
it("cleans up uploaded images when saving the message fails", async () => {
insertReturning.mockRejectedValueOnce(new Error("database unavailable"));
const body = new FormData();
body.append("image", new File(["image"], "first.png", { type: "image/png" }));
const response = await POST(new Request(`https://guide.sudloh.com/api/commission/tickets/${ticketId}/messages`, {
method: "POST", headers: { Origin: "https://guide.sudloh.com" }, body,
}), context());
expect(response.status).toBe(503);
expect(deleteObject).toHaveBeenCalledWith(writeObject.mock.calls[0][0]);
});
it("rejects an image larger than ten MiB", async () => {
const body = new FormData();
body.append("image", new File([new Uint8Array(10 * 1024 * 1024 + 1)], "large.png", { type: "image/png" }));
const response = await POST(new Request(`https://guide.sudloh.com/api/commission/tickets/${ticketId}/messages`, {
method: "POST", headers: { Origin: "https://guide.sudloh.com" }, body,
}), context());
expect(response.status).toBe(415);
expect(writeObject).not.toHaveBeenCalled();
});
});