- Renamed Lossless class to Hyperview for clarity - Renamed Lossy class to View for simplicity - Updated all imports and references throughout the codebase - Updated documentation to reflect new terminology - Fixed test files to use new class names - Added proper exports in index files
2.8 KiB
2.8 KiB
Test Helpers
This document provides documentation for the test helper functions available in the Rhizome Node test suite.
testResolverWithPlugins
A helper function for testing custom resolvers with plugins and a sequence of deltas.
Import
import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';
Signature
function testResolverWithPlugins<T>({
entityId,
plugins,
deltas,
expectedResult
}: {
entityId: string;
plugins: Record<string, ResolverPlugin>;
deltas: Delta[];
expectedResult: (result: T) => void;
}): Promise<void>;
Parameters
entityId
: The ID of the entity to testplugins
: An object mapping property names to their respective resolver pluginsdeltas
: An array ofDelta
objects to processexpectedResult
: A callback function that receives the resolved result for assertions
Return Value
A promise that resolves when the test is complete.
Example Usage
import { testResolverWithPlugins, createTestDelta } from '@test-helpers/resolver-test-helper';
import { ConcatenationPlugin } from '@src/views/resolvers/custom-resolvers/builtin-plugins';
describe('MyCustomResolver', () => {
test('should process deltas correctly', async () => {
// Run test with plugins and deltas
await testResolverWithPlugins({
entityId: 'entity1',
plugins: {
myProperty: new ConcatenationPlugin()
},
deltas: [
createTestDelta('user1', 'host1')
.setProperty('entity1', 'myProperty', 'value1')
.buildV1(),
createTestDelta('user1', 'host1')
.setProperty('entity1', 'myProperty', 'value2')
.buildV1()
],
expectedResult: (result) => {
expect(result.properties.myProperty).toBe('value1 value2');
}
});
});
});
createTestDelta
A helper function for creating test deltas with a fluent API.
Example Usage
const delta = createTestDelta('user1', 'host1')
.withTimestamp(1000)
.setProperty('entity1', 'tags', 'red', 'color1')
.buildV1();
How It Works
- Creates a new
Hyperview
instance for the test - Sets up a
CustomResolver
with the provided plugins - Ingests all provided deltas into the
Hyperview
instance - Retrieves a view for the specified entity
- Processes the view through the resolver
- Calls the
expectedResult
callback with the resolved entity
Best Practices
- Use this helper when testing custom resolvers with plugins
- The helper handles all setup and teardown of test resources
- Use
createTestDelta
for consistent delta creation in tests - The helper ensures type safety between the resolver and the expected result type
- Each test gets a fresh
Hyperview
instance automatically