Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 18, 2024
1 parent 69c1ae0 commit 57d6ab6
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,93 @@ test("clonePublicDataset method can clone a dataset", async () => {
}
}
});

test("annotationqueue crud", async () => {
const client = new Client();
const queueName = `test-queue-${uuidv4().substring(0, 8)}`;
const projectName = `test-project-${uuidv4().substring(0, 8)}`;
const queueId = uuidv4();

try {
// 1. Create an annotation queue
const queue = await client.createAnnotationQueue({
name: queueName,
description: "Initial description",
queueId,
});
expect(queue).toBeDefined();
expect(queue.name).toBe(queueName);

// 1a. Get the annotation queue
const fetchedQueue = await client.readAnnotationQueue(queue.id);
expect(fetchedQueue).toBeDefined();
expect(fetchedQueue.name).toBe(queueName);

// 1b. List annotation queues and check nameContains
const listedQueues = await toArray(
client.listAnnotationQueues({ nameContains: queueName })
);
expect(listedQueues.length).toBeGreaterThan(0);
expect(listedQueues.some((q) => q.id === queue.id)).toBe(true);

// 2. Create a run in a random project
await client.createProject({ projectName });
const runId = uuidv4();
await client.createRun({
id: runId,
name: "Test Run",
run_type: "chain",
inputs: { foo: "bar" },
outputs: { baz: "qux" },
project_name: projectName,
});

// Wait for run to be found in the db
const maxWaitTime = 30000; // 30 seconds
const startTime = Date.now();
let foundRun = null;

while (Date.now() - startTime < maxWaitTime) {
try {
foundRun = await client.readRun(runId);
if (foundRun) break;
} catch (error) {
// If run is not found, getRun might throw an error
// We'll ignore it and keep trying
}
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second before trying again
}

if (!foundRun) {
throw new Error(
`Run with ID ${runId} not found after ${maxWaitTime / 1000} seconds`
);
}

// 3. Add the run to the annotation queue
await client.addRunsToAnnotationQueue(fetchedQueue.id, [runId]);

// 4. Check that the run is in the annotation queue
const queuedRuns = await toArray(
client.listRunsFromAnnotationQueue(queue.id)
);
expect(queuedRuns.some((r) => r.id === runId)).toBe(true);

// 5. Update the annotation queue description and check that it is updated
const newDescription = "Updated description";
await client.updateAnnotationQueue(queue.id, {
name: queueName,
description: newDescription,
});
const updatedQueue = await client.readAnnotationQueue(queue.id);
expect(updatedQueue.description).toBe(newDescription);
} finally {
// 6. Delete the annotation queue
await client.deleteAnnotationQueue(queueId);

// Clean up the project
if (await client.hasProject({ projectName })) {
await client.deleteProject({ projectName });
}
}
});

0 comments on commit 57d6ab6

Please sign in to comment.