test: add missing test coverage for PR #461 improvements

- Added test for AI Agent validation positive case (tools properly connected)
- Added 3 tests for expectedFormat on resourceLocator properties

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-12-01 18:40:51 +01:00
parent f2e2d704fb
commit 10a3cdcaca
2 changed files with 100 additions and 0 deletions

View File

@@ -406,5 +406,74 @@ describe('PropertyFilter', () => {
const complex = result.common.find(p => p.name === 'complex');
expect(complex?.default).toBeUndefined();
});
it('should add expectedFormat for resourceLocator type properties', () => {
const properties = [
{
name: 'channel',
type: 'resourceLocator',
displayName: 'Channel',
description: 'The channel to send message to',
modes: [
{ name: 'list', displayName: 'From List' },
{ name: 'id', displayName: 'By ID' },
{ name: 'url', displayName: 'By URL' }
],
default: { mode: 'list', value: '' }
}
];
const result = PropertyFilter.getEssentials(properties, 'nodes-base.slack');
const channelProp = result.common.find(p => p.name === 'channel');
expect(channelProp).toBeDefined();
expect(channelProp?.expectedFormat).toBeDefined();
expect(channelProp?.expectedFormat?.structure).toEqual({
mode: 'string',
value: 'string'
});
expect(channelProp?.expectedFormat?.modes).toEqual(['list', 'id', 'url']);
expect(channelProp?.expectedFormat?.example).toBeDefined();
expect(channelProp?.expectedFormat?.example.mode).toBe('id');
expect(channelProp?.expectedFormat?.example.value).toBeDefined();
});
it('should handle resourceLocator without modes array', () => {
const properties = [
{
name: 'resource',
type: 'resourceLocator',
displayName: 'Resource',
default: { mode: 'id', value: 'test-123' }
}
];
const result = PropertyFilter.getEssentials(properties, 'nodes-base.unknownNode');
const resourceProp = result.common.find(p => p.name === 'resource');
expect(resourceProp?.expectedFormat).toBeDefined();
// Should default to common modes
expect(resourceProp?.expectedFormat?.modes).toEqual(['list', 'id']);
expect(resourceProp?.expectedFormat?.example.value).toBe('test-123');
});
it('should handle resourceLocator with no default value', () => {
const properties = [
{
name: 'item',
type: 'resourceLocator',
displayName: 'Item',
modes: [{ name: 'search' }, { name: 'id' }]
}
];
const result = PropertyFilter.getEssentials(properties, 'nodes-base.unknownNode');
const itemProp = result.common.find(p => p.name === 'item');
expect(itemProp?.expectedFormat).toBeDefined();
expect(itemProp?.expectedFormat?.modes).toEqual(['search', 'id']);
// Should use fallback value
expect(itemProp?.expectedFormat?.example.value).toBe('your-resource-id');
});
});
});

View File

@@ -1329,6 +1329,37 @@ describe('WorkflowValidator - Comprehensive Tests', () => {
expect(result.warnings.some(w => w.message.includes('AI Agent has no tools connected'))).toBe(true);
});
it('should NOT warn about AI agents WITH tools properly connected', async () => {
const workflow = {
nodes: [
{
id: '1',
name: 'Calculator Tool',
type: 'n8n-nodes-base.httpRequest',
position: [100, 100],
parameters: {}
},
{
id: '2',
name: 'Agent',
type: '@n8n/n8n-nodes-langchain.agent',
position: [300, 100],
parameters: {}
}
],
connections: {
'Calculator Tool': {
ai_tool: [[{ node: 'Agent', type: 'ai_tool', index: 0 }]]
}
}
} as any;
const result = await validator.validateWorkflow(workflow as any);
// Should NOT have warning about missing tools
expect(result.warnings.some(w => w.message.includes('AI Agent has no tools connected'))).toBe(false);
});
it('should suggest community package setting for AI tools', async () => {
const workflow = {
nodes: [