test(api): cover assistant import export tools
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { SystemRole } from "@capakraken/shared";
|
||||||
|
import {
|
||||||
|
createToolContext,
|
||||||
|
executeTool,
|
||||||
|
resetAssistantImportToolTestState,
|
||||||
|
} from "./assistant-tools-import-dispo-webhooks-test-helpers.js";
|
||||||
|
|
||||||
|
describe("assistant export tools", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await resetAssistantImportToolTestState();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exports resources CSV through the real import/export router path", async () => {
|
||||||
|
const ctx = createToolContext(
|
||||||
|
{
|
||||||
|
resource: {
|
||||||
|
findMany: vi.fn().mockResolvedValue([
|
||||||
|
{
|
||||||
|
eid: "EMP-001",
|
||||||
|
displayName: "Carol Danvers",
|
||||||
|
email: "carol@example.com",
|
||||||
|
chapter: "Delivery",
|
||||||
|
lcrCents: 8000,
|
||||||
|
ucrCents: 12000,
|
||||||
|
currency: "EUR",
|
||||||
|
chargeabilityTarget: 0.8,
|
||||||
|
dynamicFields: {},
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
blueprint: {
|
||||||
|
findMany: vi.fn().mockResolvedValue([]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ userRole: SystemRole.CONTROLLER },
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await executeTool("export_resources_csv", "{}", ctx);
|
||||||
|
|
||||||
|
expect(JSON.parse(result.content)).toEqual({
|
||||||
|
format: "csv",
|
||||||
|
lineCount: 2,
|
||||||
|
csv: "eid,displayName,email,chapter,lcrCents,ucrCents,currency,chargeabilityTarget\nEMP-001,Carol Danvers,carol@example.com,Delivery,8000,12000,EUR,0.8",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { PermissionKey, SystemRole } from "@capakraken/shared";
|
||||||
|
import {
|
||||||
|
createToolContext,
|
||||||
|
executeTool,
|
||||||
|
resetAssistantImportToolTestState,
|
||||||
|
} from "./assistant-tools-import-dispo-webhooks-test-helpers.js";
|
||||||
|
|
||||||
|
describe("assistant import tools", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await resetAssistantImportToolTestState();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("requires importData permission for CSV imports", async () => {
|
||||||
|
const ctx = createToolContext(
|
||||||
|
{
|
||||||
|
auditLog: { create: vi.fn() },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userRole: SystemRole.MANAGER,
|
||||||
|
permissions: [],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await executeTool(
|
||||||
|
"import_csv_data",
|
||||||
|
JSON.stringify({
|
||||||
|
entityType: "resources",
|
||||||
|
rows: [{ eid: "EMP-001", displayName: "Carol Danvers" }],
|
||||||
|
dryRun: true,
|
||||||
|
}),
|
||||||
|
ctx,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(JSON.parse(result.content)).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
error: expect.stringContaining(PermissionKey.IMPORT_DATA),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user