Files
mem0/mem0-ts/src/client/tests/integration/batch.test.ts
T

87 lines
2.3 KiB
TypeScript

/**
* Integration tests: Batch operations.
*
* Tests batch update and batch delete against the real API.
*
* Run: MEM0_API_KEY=your-key npx jest batch.test.ts --forceExit
*/
import { MemoryClient } from "../../mem0";
import { randomUUID } from "crypto";
import {
describeIntegration,
createTestClient,
suppressTelemetryNoise,
seedTestMemories,
waitForMemories,
cleanupTestUser,
} from "./helpers";
jest.setTimeout(120_000);
const TEST_USER_ID = `integration-batch-${randomUUID()}`;
describeIntegration("MemoryClient Integration — Batch Operations", () => {
let client: MemoryClient;
let cleanup: () => void;
let memoryIds: string[] = [];
beforeAll(async () => {
cleanup = suppressTelemetryNoise();
client = createTestClient();
memoryIds = await seedTestMemories(client, TEST_USER_ID);
});
afterAll(async () => {
await cleanupTestUser(client, TEST_USER_ID);
cleanup();
});
test("batch updates memories", async () => {
expect(memoryIds.length).toBeGreaterThanOrEqual(1);
const batchPayload = memoryIds
.slice(0, Math.min(2, memoryIds.length))
.map((id) => ({
memoryId: id,
text: `Batch updated content for ${id}`,
}));
const result = await client.batchUpdate(batchPayload);
expect(result).toBeDefined();
// Verify the update took effect on at least one memory
const updated = await client.get(memoryIds[0]);
expect(typeof updated.memory).toBe("string");
});
test("batch deletes throwaway memories", async () => {
// Add a throwaway memory, wait for it, then batch-delete
await client.add(
[
{
role: "user" as const,
content: "Temporary memory for batch delete test.",
},
{ role: "assistant" as const, content: "Noted!" },
],
{ user_id: TEST_USER_ID },
);
// Wait for new memory to appear
const before = await waitForMemories(
client,
TEST_USER_ID,
memoryIds.length + 1,
);
const throwawayIds = before
.filter((m) => !memoryIds.includes(m.id))
.map((m) => m.id);
// Assert we actually have something to delete
expect(throwawayIds.length).toBeGreaterThan(0);
const result = await client.batchDelete(throwawayIds);
expect(result).toBeDefined();
});
});