UNPKG

@stillrivercode/agentic-workflow-template

Version:

NPM package to create AI-powered GitHub workflow automation projects

156 lines (137 loc) 4.41 kB
const { validateProjectName, validateSystem, validateApiKey, validateGitHubOrg, } = require('../validators'); describe('Validators', () => { describe('validateProjectName', () => { test('should accept valid project names', () => { const validNames = [ 'my-project', 'my_project', 'myproject', 'my-project-123', 'project123', 'a', // single character 'my-very-long-project-name-that-is-still-valid', ]; validNames.forEach((name) => { expect(() => validateProjectName(name)).not.toThrow(); expect(validateProjectName(name)).toBe(true); }); }); test('should reject invalid project names', () => { const invalidNames = [ '', // empty ' ', // whitespace only 'My-Project', // uppercase 'my project', // contains space 'my/project', // contains slash 'my\\project', // contains backslash '../invalid', // path traversal '.hidden', // starts with dot '-project', // starts with hyphen 'project-', // ends with hyphen 'a'.repeat(215), // too long (npm limit is 214) ]; invalidNames.forEach((name) => { expect(() => validateProjectName(name)).toThrow(); }); }); test('should handle reserved names', () => { const reservedNames = [ 'node', 'npm', 'core', 'console', 'global', 'process', ]; reservedNames.forEach((name) => { expect(() => validateProjectName(name)).toThrow(); }); }); test('should handle edge cases', () => { // Test reasonable length limits const longButValid = 'a'.repeat(50); expect(() => validateProjectName(longButValid)).not.toThrow(); // Test exactly at npm limit const atLimit = 'a'.repeat(214); expect(() => validateProjectName(atLimit)).not.toThrow(); }); }); describe('validateApiKey', () => { test('should accept valid OpenRouter API keys', () => { const validKeys = [ 'sk-or-v1-abcdef1234567890abcdef1234567890', 'sk-or-v1-' + 'a'.repeat(40), 'sk-or-test-key-123456789', ]; validKeys.forEach((key) => { expect(validateApiKey(key)).toBe(true); }); }); test('should reject invalid API keys', () => { const invalidKeys = [ '', // empty ' ', // whitespace only 'invalid-key', // wrong format 'sk-', // too short 'sk-or-', // too short 'sk-or-' + 'a'.repeat(200), // too long 'sk-or-v1-invalid@key!', // invalid characters ]; invalidKeys.forEach((key) => { const result = validateApiKey(key); expect(typeof result).toBe('string'); // Should return error message expect(result).not.toBe(true); }); }); }); describe('validateGitHubOrg', () => { test('should accept valid GitHub organizations', () => { const validOrgs = [ 'myorg', 'my-org', 'MyOrg123', 'github', 'microsoft', 'a', 'a'.repeat(39), // at limit ]; validOrgs.forEach((org) => { expect(validateGitHubOrg(org)).toBe(true); }); }); test('should reject invalid GitHub organizations', () => { const invalidOrgs = [ '', // empty ' ', // whitespace only 'my_org', // underscore not allowed 'my org', // space not allowed '-org', // starts with hyphen 'org-', // ends with hyphen 'my--org', // consecutive hyphens 'a'.repeat(40), // too long 'org@name', // invalid characters ]; invalidOrgs.forEach((org) => { const result = validateGitHubOrg(org); expect(typeof result).toBe('string'); // Should return error message expect(result).not.toBe(true); }); }); }); describe('validateSystem', () => { test('should validate system requirements', async () => { // This test mainly ensures the function runs without error // since it checks real system conditions await expect(validateSystem()).resolves.not.toThrow(); }); test('should be callable multiple times', async () => { await expect(validateSystem()).resolves.not.toThrow(); await expect(validateSystem()).resolves.not.toThrow(); }); }); });