@arke-institute/klados-testing
v0.3.3
Published
Test utilities for klados workers on the Arke network
Downloads
751
Maintainers
Readme
@arke-institute/klados-testing
Test utilities for klados workers on the Arke network.
Installation
npm install --save-dev @arke-institute/klados-testingUsage
Configure the Test Client
Call configureTestClient once in your test setup:
import { configureTestClient } from '@arke-institute/klados-testing';
configureTestClient({
apiBase: 'https://arke-v1.arke.institute',
userKey: process.env.ARKE_USER_KEY!,
network: 'test',
});Create Test Fixtures
import {
createCollection,
createEntity,
deleteEntity,
} from '@arke-institute/klados-testing';
// Create a collection
const collection = await createCollection({
label: 'Test Collection',
allowedTypes: ['document'],
});
// Create an entity in the collection
const entity = await createEntity({
type: 'document',
properties: { title: 'Test' },
collectionId: collection.id,
});
// Cleanup
await deleteEntity(entity.id);
await deleteEntity(collection.id);Invoke and Verify Klados
import {
invokeKlados,
waitForKladosLog,
assertLogCompleted,
assertLogHasMessages,
} from '@arke-institute/klados-testing';
// Invoke a klados
const result = await invokeKlados({
kladosId: 'klados_xxx',
targetEntity: entity.id,
targetCollection: collection.id,
jobCollection: jobCollection.id,
confirm: true,
});
// Wait for completion
const log = await waitForKladosLog(result.job_collection!, {
timeout: 30000,
pollInterval: 1000,
});
// Verify with assertions
assertLogCompleted(log);
assertLogHasMessages(log, [
{ level: 'info', textContains: 'Processing' },
{ level: 'success', textContains: 'completed' },
]);API Reference
Configuration
configureTestClient(config)- Configure the test clientgetConfig()- Get current config (throws if not configured)resetTestClient()- Reset configuration
Entity Operations
createEntity(options)- Create an entitygetEntity(id)- Get an entity by IDdeleteEntity(id)- Delete an entitycreateCollection(options)- Create a collectiongetCollectionEntities(id)- Get entities in a collection
Log Utilities
getKladosLog(id)- Get a klados log by IDgetFirstLogFromCollection(id)- Get first_log relationship from collectionwaitForKladosLog(jobCollectionId, options?)- Wait for log completiongetLogMessages(log)- Extract messages from loggetLogEntry(log)- Extract entry details from log
Klados Invocation
invokeKlados(options)- Invoke a klados worker
Assertions
assertLogCompleted(log)- Assert log completed successfullyassertLogFailed(log, expectedCode?)- Assert log failed with errorassertLogHasMessages(log, criteria)- Assert log contains specific messagesassertLogMessageCount(log, minCount)- Assert minimum message countassertLogHasHandoff(log, handoffType)- Assert log has specific handoff
Helpers
sleep(ms)- Sleep for durationlog(message, data?)- Log with timestampapiRequest(method, path, body?)- Make raw API request
Environment Variables
Your tests should set these environment variables:
ARKE_USER_KEY- User API key (uk_...) for authenticationARKE_API_BASE- API base URL (default: https://arke-v1.arke.institute)ARKE_NETWORK- Network to use: 'test' or 'main' (default: test)
License
MIT
