|
1 | 1 | import type { ResourceMapperField } from 'n8n-workflow'; |
2 | | -import { isResourceMapperFieldListStale } from './nodeTypesUtils'; |
| 2 | +import { isCommunityPackageName, isResourceMapperFieldListStale } from './nodeTypesUtils'; |
3 | 3 |
|
4 | 4 | describe('isResourceMapperFieldListStale', () => { |
5 | 5 | const baseField: ResourceMapperField = { |
@@ -73,3 +73,57 @@ describe('isResourceMapperFieldListStale', () => { |
73 | 73 | expect(isResourceMapperFieldListStale(oldFields, newFields)).toBe(true); |
74 | 74 | }); |
75 | 75 | }); |
| 76 | + |
| 77 | +describe('isCommunityPackageName', () => { |
| 78 | + // Standard community package names |
| 79 | + it('should identify standard community node package names', () => { |
| 80 | + expect(isCommunityPackageName('n8n-nodes-example')).toBe(true); |
| 81 | + expect(isCommunityPackageName('n8n-nodes-custom')).toBe(true); |
| 82 | + expect(isCommunityPackageName('n8n-nodes-test')).toBe(true); |
| 83 | + }); |
| 84 | + |
| 85 | + // Scoped package names |
| 86 | + it('should identify scoped community node package names', () => { |
| 87 | + expect(isCommunityPackageName('@username/n8n-nodes-example')).toBe(true); |
| 88 | + expect(isCommunityPackageName('@org/n8n-nodes-custom')).toBe(true); |
| 89 | + expect(isCommunityPackageName('@test-scope/n8n-nodes-test-name')).toBe(true); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should identify scoped packages with other characters', () => { |
| 93 | + expect(isCommunityPackageName('n8n-nodes-my_package')).toBe(true); |
| 94 | + expect(isCommunityPackageName('@user/n8n-nodes-with_underscore')).toBe(true); |
| 95 | + expect(isCommunityPackageName('@user_name/n8n-nodes-example')).toBe(true); |
| 96 | + expect(isCommunityPackageName('@n8n-io/n8n-nodes-test')).toBe(true); |
| 97 | + expect(isCommunityPackageName('@n8n.io/n8n-nodes-test')).toBe(true); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should handle mixed cases', () => { |
| 101 | + expect(isCommunityPackageName('@user-name_org/n8n-nodes-mixed-case_example')).toBe(true); |
| 102 | + expect(isCommunityPackageName('@mixed_style-org/n8n-nodes-complex_name-format')).toBe(true); |
| 103 | + expect(isCommunityPackageName('@my.mixed_style-org/n8n-nodes-complex_name-format')).toBe(true); |
| 104 | + }); |
| 105 | + |
| 106 | + // Official n8n packages that should not be identified as community packages |
| 107 | + it('should not identify official n8n packages as community nodes', () => { |
| 108 | + expect(isCommunityPackageName('@n8n/n8n-nodes-example')).toBe(false); |
| 109 | + expect(isCommunityPackageName('n8n-nodes-base')).toBe(false); |
| 110 | + }); |
| 111 | + |
| 112 | + // Additional edge cases |
| 113 | + it('should handle edge cases correctly', () => { |
| 114 | + // Non-matching patterns |
| 115 | + expect(isCommunityPackageName('not-n8n-nodes')).toBe(false); |
| 116 | + expect(isCommunityPackageName('n8n-core')).toBe(false); |
| 117 | + |
| 118 | + // With node name after package |
| 119 | + expect(isCommunityPackageName('n8n-nodes-example.NodeName')).toBe(true); |
| 120 | + expect(isCommunityPackageName('@user/n8n-nodes-example.NodeName')).toBe(true); |
| 121 | + }); |
| 122 | + |
| 123 | + // Multiple executions to test regex state |
| 124 | + it('should work correctly with multiple consecutive calls', () => { |
| 125 | + expect(isCommunityPackageName('@user/n8n-nodes-example')).toBe(true); |
| 126 | + expect(isCommunityPackageName('n8n-nodes-base')).toBe(false); |
| 127 | + expect(isCommunityPackageName('@test-scope/n8n-nodes-test')).toBe(true); |
| 128 | + }); |
| 129 | +}); |
0 commit comments