metadataapi/tagapi/bulkeditapi als Backend-Voraussetzung. MetadataForm passt sich der Felddefinition an und warnt vor Verwerfen ungespeicherter Aenderungen, TagInput schlaegt Tags vor und ist per Pfeiltasten/Enter bedienbar, Massenbearbeitung wendet Tags auf beliebig grosse Auswahlen in einem Aufruf an. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { applyBulkEdit } from "./bulkEditApi";
|
|
|
|
const ORIGINAL_ENV = process.env;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...ORIGINAL_ENV, NEXT_PUBLIC_BULK_EDIT_API_URL: "http://backend.test", NEXT_PUBLIC_USER_ID: "user-a" };
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = ORIGINAL_ENV;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("bulkEditApi", () => {
|
|
it("sendet alle ausgewaehlten dokument-ids in einem aufruf", async () => {
|
|
const ids = Array.from({ length: 200 }, (_, i) => `doc-${i}`);
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ applied: ids, skipped: [] }), { status: 200 }));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
const result = await applyBulkEdit({ documentIds: ids, addTagIds: ["tag-1"] });
|
|
|
|
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
|
expect(body.document_ids).toHaveLength(200);
|
|
expect(body.actor).toBe("user-a");
|
|
expect(result.applied).toHaveLength(200);
|
|
});
|
|
});
|