/**
* Agent Synch MCP Server - Utility Tests
*/
import { describe, it, expect } from 'vitest';
import { sanitizeId, generateId } from './utils.js';
describe('sanitizeId', () => {
it('should preserve alphanumeric characters', () => {
expect(sanitizeId('project123')).toBe('project123');
});
it('should preserve hyphens and underscores', () => {
expect(sanitizeId('my-project_v2')).toBe('my-project_v2');
});
it('should replace special characters with underscore', () => {
expect(sanitizeId('path/to/file.ts')).toBe('path_to_file_ts');
});
it('should handle spaces', () => {
expect(sanitizeId('my project')).toBe('my_project');
});
it('should handle empty string', () => {
expect(sanitizeId('')).toBe('');
});
it('should handle mixed special characters', () => {
// @#$%^&*() = 9 special characters = 9 underscores
expect(sanitizeId('test@#$%^&*()file')).toBe('test_________file');
});
});
describe('generateId', () => {
it('should generate ID with correct prefix', () => {
const id = generateId('bug');
expect(id).toMatch(/^bug_\d+_[a-z0-9]{5}$/);
});
it('should generate ID with evt prefix', () => {
const id = generateId('evt');
expect(id).toMatch(/^evt_\d+_[a-z0-9]{5}$/);
});
it('should generate unique IDs', () => {
const id1 = generateId('test');
const id2 = generateId('test');
expect(id1).not.toBe(id2);
});
it('should include timestamp', () => {
const before = Date.now();
const id = generateId('ts');
const after = Date.now();
const parts = id.split('_');
const timestamp = parseInt(parts[1], 10);
expect(timestamp).toBeGreaterThanOrEqual(before);
expect(timestamp).toBeLessThanOrEqual(after);
});
});