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
@@ -0,0 +1,113 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
loadContext: vi.fn(),
|
||||
requirePermission: vi.fn(),
|
||||
ownLeave: vi.fn(),
|
||||
leaveApprovals: vi.fn(),
|
||||
ownSick: vi.fn(),
|
||||
ownRequests: vi.fn(),
|
||||
requestApprovals: vi.fn(),
|
||||
directory: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: async () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrAccess.server", () => ({
|
||||
loadHrContext: mocks.loadContext,
|
||||
notFoundResponse: () => new Response("Not Found", { status: 404 }),
|
||||
requireHrPermission: mocks.requirePermission,
|
||||
hrHasPermission: (ctx: { permissions: string[] }, permission: string) =>
|
||||
ctx.permissions.includes(permission),
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrLeaveService.server", () => ({
|
||||
listOwnVacationRequests: mocks.ownLeave,
|
||||
listForApprover: mocks.leaveApprovals,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrSickLeaveService.server", () => ({
|
||||
listOwnSickLeave: mocks.ownSick,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrRequestService.server", () => ({
|
||||
listOwnRequests: mocks.ownRequests,
|
||||
listForApprover: mocks.requestApprovals,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/hrService.server", () => ({
|
||||
listDirectoryForViewer: mocks.directory,
|
||||
}));
|
||||
|
||||
import { loader } from "./app.$tenant/hr/index";
|
||||
|
||||
function args() {
|
||||
return {
|
||||
request: new Request("https://app.example.test/acme/hr"),
|
||||
params: { tenant: "acme" },
|
||||
context: {},
|
||||
} as never;
|
||||
}
|
||||
|
||||
describe("HR hub loader", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.loadContext.mockResolvedValue({
|
||||
tenantId: "tenant-1",
|
||||
userId: "user-1",
|
||||
permissions: ["hr.read_own"],
|
||||
hasModule: true,
|
||||
});
|
||||
mocks.ownLeave.mockResolvedValue([{ status: "submitted" }, { status: "approved" }]);
|
||||
mocks.ownSick.mockResolvedValue([{ status: "reported" }]);
|
||||
mocks.ownRequests.mockResolvedValue([{ status: "clarification" }]);
|
||||
mocks.leaveApprovals.mockResolvedValue([]);
|
||||
mocks.requestApprovals.mockResolvedValue([]);
|
||||
mocks.directory.mockResolvedValue([{ userId: "user-1" }]);
|
||||
});
|
||||
|
||||
it("keeps a generic tenant admin in the self-service area without HR permissions", async () => {
|
||||
const response = await loader(args());
|
||||
const body = (await response.json()) as { vm: { openTaskCount: number; administration: { visible: boolean }; myTeam: { visible: boolean } } };
|
||||
|
||||
expect(body.vm.openTaskCount).toBe(3);
|
||||
expect(body.vm.administration.visible).toBe(false);
|
||||
expect(body.vm.myTeam.visible).toBe(false);
|
||||
expect(mocks.directory).toHaveBeenCalledWith({
|
||||
tenantId: "tenant-1",
|
||||
viewerUserId: "user-1",
|
||||
canReadAll: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("derives team and administration from granular HR capabilities", async () => {
|
||||
mocks.loadContext.mockResolvedValue({
|
||||
tenantId: "tenant-1",
|
||||
userId: "hr-1",
|
||||
permissions: ["hr.read_own", "hr.read_all", "hr.write", "hr.leave.approve"],
|
||||
hasModule: true,
|
||||
});
|
||||
mocks.directory.mockResolvedValue([{ userId: "hr-1" }, { userId: "employee-1" }]);
|
||||
mocks.leaveApprovals.mockResolvedValue([{ id: "leave-1" }]);
|
||||
|
||||
const response = await loader(args());
|
||||
const body = (await response.json()) as { vm: { administration: { visible: boolean }; myTeam: { visible: boolean; count: number } } };
|
||||
|
||||
expect(body.vm.administration.visible).toBe(true);
|
||||
expect(body.vm.myTeam.visible).toBe(true);
|
||||
expect(body.vm.myTeam.count).toBe(2);
|
||||
});
|
||||
|
||||
it("does not query HR rows when the module is disabled", async () => {
|
||||
mocks.loadContext.mockResolvedValue({
|
||||
tenantId: "tenant-1",
|
||||
userId: "user-1",
|
||||
permissions: [],
|
||||
hasModule: false,
|
||||
});
|
||||
|
||||
const response = await loader(args());
|
||||
const body = (await response.json()) as { vm: { moduleActive: boolean } };
|
||||
|
||||
expect(body.vm.moduleActive).toBe(false);
|
||||
expect(mocks.ownLeave).not.toHaveBeenCalled();
|
||||
expect(mocks.directory).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user