Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+96
@@ -0,0 +1,96 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
loadContext: vi.fn(),
|
||||
requirePermission: vi.fn(),
|
||||
createFile: vi.fn(),
|
||||
createDocumentWithLink: vi.fn(),
|
||||
hardDeleteFile: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/integrations/hrAccess.server", () => ({
|
||||
loadHrContext: mocks.loadContext,
|
||||
requireHrPermission: mocks.requirePermission,
|
||||
badRequestResponse: () => new Response("Bad Request", { status: 400 }),
|
||||
notFoundResponse: () => new Response("Not Found", { status: 404 }),
|
||||
hrActionErrorResponse: () => new Response("Upload failed", { status: 500 }),
|
||||
}));
|
||||
vi.mock("~/utils/integrations/fileService.server", () => ({
|
||||
createFileFromBytes: mocks.createFile,
|
||||
hardDeleteFile: mocks.hardDeleteFile,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrService.server", () => ({
|
||||
archiveDocument: vi.fn(),
|
||||
createDocumentWithLink: mocks.createDocumentWithLink,
|
||||
listEmployeeDocuments: vi.fn(),
|
||||
}));
|
||||
vi.mock("~/utils/integrations/storageService", () => ({
|
||||
StorageScanRejectedError: class StorageScanRejectedError extends Error {},
|
||||
}));
|
||||
|
||||
import { action } from "./app.$tenant/hr/my-documents";
|
||||
|
||||
function uploadArgs() {
|
||||
const form = new FormData();
|
||||
const file = new File(["verified bytes"], "zeugnis.pdf", { type: "application/pdf" });
|
||||
if (typeof file.arrayBuffer !== "function") {
|
||||
Object.defineProperty(file, "arrayBuffer", {
|
||||
value: async () => new TextEncoder().encode("verified bytes").buffer,
|
||||
});
|
||||
}
|
||||
form.set("intent", "upload-doc");
|
||||
form.set("title", "Arbeitszeugnis");
|
||||
form.set("documentKind", "certificate");
|
||||
form.set("file", file);
|
||||
return {
|
||||
request: { formData: async () => form },
|
||||
params: { tenant: "acme" },
|
||||
context: {},
|
||||
} as never;
|
||||
}
|
||||
|
||||
describe("HR personnel document upload", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.loadContext.mockResolvedValue({
|
||||
tenantId: "tenant-1",
|
||||
userId: "employee-1",
|
||||
permissions: ["hr.read_own"],
|
||||
hasModule: true,
|
||||
});
|
||||
mocks.createFile.mockResolvedValue({ id: "file-1" });
|
||||
mocks.createDocumentWithLink.mockResolvedValue({ id: "document-1" });
|
||||
mocks.hardDeleteFile.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("creates the File and its HR document/link through the atomic service", async () => {
|
||||
const response = await action(uploadArgs());
|
||||
|
||||
await expect(response.json()).resolves.toEqual({
|
||||
intent: "upload-doc",
|
||||
ok: true,
|
||||
messageKey: "hr.documents.toast.uploaded",
|
||||
});
|
||||
expect(mocks.createDocumentWithLink).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
tenantId: "tenant-1",
|
||||
employeeUserId: "employee-1",
|
||||
uploadedByUserId: "employee-1",
|
||||
fileId: "file-1",
|
||||
}),
|
||||
);
|
||||
expect(mocks.hardDeleteFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("compensates the accepted File when document/link creation rolls back", async () => {
|
||||
mocks.createDocumentWithLink.mockRejectedValue(new Error("link failed"));
|
||||
|
||||
const response = await action(uploadArgs());
|
||||
|
||||
expect(response.status).toBe(500);
|
||||
expect(mocks.hardDeleteFile).toHaveBeenCalledWith({
|
||||
tenantId: "tenant-1",
|
||||
fileId: "file-1",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user