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
+106
@@ -0,0 +1,106 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
requireProjectView: vi.fn(),
|
||||
exportProjectListCsv: vi.fn(),
|
||||
listPipelines: vi.fn(),
|
||||
isDemoDataUiEnabled: vi.fn(),
|
||||
projectReadPermissions: ["projects.read_all", "projects.read_own", "projects.read_own_pl", "projects.read_own_member"],
|
||||
ProjectServiceError: class ProjectServiceError extends Error {
|
||||
readonly messageKey: string;
|
||||
constructor(messageKey: string) {
|
||||
super(messageKey);
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/integrations/projects/projectAccess.server", () => ({
|
||||
PROJECT_READ_PERMISSIONS: mocks.projectReadPermissions,
|
||||
requireProjectView: mocks.requireProjectView,
|
||||
}));
|
||||
vi.mock("~/utils/integrations/projects/projectService.server", () => ({
|
||||
exportProjectListCsv: mocks.exportProjectListCsv,
|
||||
listPipelines: mocks.listPipelines,
|
||||
ProjectServiceError: mocks.ProjectServiceError,
|
||||
}));
|
||||
vi.mock("~/utils/services/.server/demoDataUi.server", () => ({ isDemoDataUiEnabled: mocks.isDemoDataUiEnabled }));
|
||||
|
||||
import { loader } from "./projects.export";
|
||||
|
||||
describe("project list CSV resource", () => {
|
||||
const ctx = { tenantId: "tenant-1", tenantSlug: "acme", userId: "user-1", permissions: ["projects.read_own"] };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.requireProjectView.mockResolvedValue(ctx);
|
||||
mocks.exportProjectListCsv.mockResolvedValue('"Nummer","Name"\n"P-1","Dach"\n');
|
||||
mocks.listPipelines.mockResolvedValue([
|
||||
{ id: "pipe-default", isDefault: true },
|
||||
{ id: "pipe-1", isDefault: false },
|
||||
]);
|
||||
mocks.isDemoDataUiEnabled.mockReturnValue(true);
|
||||
});
|
||||
|
||||
it("returns a loader-only CSV response with the complete list query", async () => {
|
||||
const request = new Request(
|
||||
"https://app.example.test/acme/projects/export?pipelineId=pipe-1&owner=owner-1&kundentyp=privatperson&q=dach&onlyMine=1&sort=name_asc&demo=show"
|
||||
);
|
||||
const response = await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
expect(mocks.requireProjectView).toHaveBeenCalledWith({ request, params: { tenant: "acme" } }, mocks.projectReadPermissions);
|
||||
expect(mocks.exportProjectListCsv).toHaveBeenCalledWith({
|
||||
tenantId: "tenant-1",
|
||||
ctx,
|
||||
filters: {
|
||||
pipelineId: "pipe-1",
|
||||
q: "dach",
|
||||
onlyMine: true,
|
||||
includeDemoData: true,
|
||||
// The download carries the same facets the list is showing — including
|
||||
// the tag selection, since export, list and board share one definition.
|
||||
facets: { owners: ["owner-1"], customerTypes: ["privatperson"], tagIds: [], periods: [], periodFrom: null, periodTo: null, valueBands: [] },
|
||||
},
|
||||
sort: "name_asc",
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("Content-Type")).toBe("text/csv; charset=utf-8");
|
||||
expect(response.headers.get("Content-Disposition")).toBe('attachment; filename="projects.csv"');
|
||||
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
|
||||
await expect(response.text()).resolves.toContain('"P-1","Dach"');
|
||||
});
|
||||
|
||||
it("falls back to the default board so the CSV matches the bound list", async () => {
|
||||
// The list resolves an absent pipelineId to the default board; a download
|
||||
// spanning every board would not be what the screen was showing.
|
||||
const request = new Request("https://app.example.test/acme/projects/export?q=dach");
|
||||
|
||||
await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
expect(mocks.exportProjectListCsv).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ filters: expect.objectContaining({ pipelineId: "pipe-default" }) })
|
||||
);
|
||||
});
|
||||
|
||||
it("ignores the demo query outside an enabled staging environment", async () => {
|
||||
mocks.isDemoDataUiEnabled.mockReturnValue(false);
|
||||
const request = new Request("https://app.example.test/acme/projects/export?demo=show&sort=invalid");
|
||||
|
||||
await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
expect(mocks.exportProjectListCsv).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ filters: expect.objectContaining({ includeDemoData: false }), sort: "updated_desc" })
|
||||
);
|
||||
});
|
||||
|
||||
it("returns a private 413 response when the safe export limit is exceeded", async () => {
|
||||
mocks.exportProjectListCsv.mockRejectedValue(new mocks.ProjectServiceError("projects.error.exportTooLarge"));
|
||||
const request = new Request("https://app.example.test/acme/projects/export");
|
||||
|
||||
const response = await loader({ request, params: { tenant: "acme" }, context: {} } as never);
|
||||
|
||||
expect(response.status).toBe(413);
|
||||
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
|
||||
await expect(response.json()).resolves.toEqual({ error: "projects.error.exportTooLarge" });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user