Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/scripts/demo-pro-seed/search-batches.test.ts
T

36 lines
1.3 KiB
TypeScript

import { OUTBOX_MAX_PAYLOAD_BYTES } from "@hivegrid/db/outbox";
import { describe, expect, it } from "vitest";
import { generateDemoProSeed } from "./generator";
import { generateOperationalGraph } from "./operations";
import { splitSearchPayload } from "./search-batches";
describe("demo-pro search outbox batches", () => {
it("keeps the largest generated task payloads below the outbox hard limit", () => {
const graph = generateDemoProSeed();
const operational = generateOperationalGraph(graph);
const tenantId = "tenant-demo-pro";
const documents = operational.tasks.map((task) => ({
id: task.id,
tenantId,
title: task.title,
description: task.description,
status: task.status,
priority: task.priority,
linkedEntityId: task.projectId,
deadline: task.deadline,
}));
const payloadFor = (batch: readonly (typeof documents)[number][]) => ({
action: "upsert-batch",
indexName: "tasks",
tenantId,
documents: batch,
});
const batches = splitSearchPayload(documents, payloadFor);
expect(batches.flat()).toEqual(documents);
expect(batches.length).toBeLessThan(20);
expect(batches.every((batch) => Buffer.byteLength(JSON.stringify(payloadFor(batch)), "utf8") < OUTBOX_MAX_PAYLOAD_BYTES)).toBe(true);
});
});