Fixed critical bugs affecting test suite: **Clustering (2 tests fixed)** - Fixed entity.type field reference bug in _getItemsByField() - Changed entity.noun to entity.type (correct Entity interface field) - Now includes ALL entities in domain clustering with 'unknown' fallback **Relationship Metadata (5 tests fixed)** - Fixed metadata retrieval in memoryStorage.ts getVerbs() - Changed metadata.data to metadata.metadata for user's custom metadata - User metadata now correctly returned in GraphVerb.metadata field **Delete Relationship Cleanup (2 tests fixed)** - Added deleteVerbMetadata() method to BaseStorage - Fixed deleteVerb_internal() in memoryStorage to delete verb metadata - Relationships now properly cleaned up when entities are deleted **Validation (1 test fixed)** - Removed overly restrictive self-referential relationship check - Self-relationships now allowed (valid in graph systems) Test results: 27 failures → 17 failures (37% improvement) All 467 tests now enabled (0 skipped)
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
/**
|
|
* Test to verify correct API parameter usage
|
|
* Reproduces Brain Cloud issue where 'filter' was used instead of 'where'
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
import { Brainy } from '../../src/index.js'
|
|
import { NounType } from '../../src/types/graphTypes.js'
|
|
|
|
describe('API Parameter Validation', () => {
|
|
let brain: Brainy
|
|
|
|
beforeAll(async () => {
|
|
brain = new Brainy({
|
|
storage: { type: 'memory' }
|
|
})
|
|
await brain.init()
|
|
|
|
// Add test data
|
|
await brain.add({
|
|
data: 'Alice',
|
|
type: NounType.User,
|
|
metadata: { category: 'test-category', status: 'active' }
|
|
})
|
|
await brain.add({
|
|
data: 'Bob',
|
|
type: NounType.User,
|
|
metadata: { category: 'other-category', status: 'active' }
|
|
})
|
|
await brain.add({
|
|
data: 'Charlie',
|
|
type: NounType.User,
|
|
metadata: { category: 'test-category', status: 'inactive' }
|
|
})
|
|
})
|
|
|
|
it('should use "where" parameter for metadata filtering', async () => {
|
|
const results = await brain.find({
|
|
where: { category: 'test-category' },
|
|
limit: 10
|
|
})
|
|
|
|
expect(results).toHaveLength(2)
|
|
expect(results.map(r => r.entity.data).sort()).toEqual(['Alice', 'Charlie'])
|
|
})
|
|
|
|
it('should IGNORE unknown "filter" parameter (reproduces Brain Cloud bug)', async () => {
|
|
// This is what Brain Cloud was doing - using 'filter' instead of 'where'
|
|
const results = await brain.find({
|
|
filter: { category: 'test-category' } as any, // Wrong parameter!
|
|
limit: 10
|
|
})
|
|
|
|
// Should return ALL results because filter is ignored
|
|
expect(results.length).toBeGreaterThanOrEqual(2)
|
|
})
|
|
|
|
it('should demonstrate the difference between correct and incorrect API usage', async () => {
|
|
// CORRECT: Using 'where'
|
|
const correctResults = await brain.find({
|
|
where: { category: 'test-category' },
|
|
limit: 10
|
|
})
|
|
|
|
// INCORRECT: Using 'filter' (what Brain Cloud did)
|
|
const incorrectResults = await brain.find({
|
|
filter: { category: 'test-category' } as any,
|
|
limit: 10
|
|
})
|
|
|
|
// Correct usage filters results
|
|
expect(correctResults).toHaveLength(2)
|
|
|
|
// Incorrect usage returns more results (filter ignored)
|
|
expect(incorrectResults.length).toBeGreaterThan(correctResults.length)
|
|
})
|
|
})
|