UNPKG

@graphikartistry/cursor-doc-automation

Version:

Cursor IDE extension for autonomous documentation and ticket management

75 lines (60 loc) 2.59 kB
import { DocumentationService } from '../services/documentationService'; import { execSync } from 'child_process'; // Mock the child_process module jest.mock('child_process', () => ({ execSync: jest.fn() })); describe('DocumentationService', () => { let docService: DocumentationService; beforeEach(() => { docService = new DocumentationService(); // Reset all mocks before each test jest.clearAllMocks(); }); describe('analyzeChanges', () => { it('should analyze recent changes successfully', async () => { // Mock the git diff output (execSync as jest.Mock).mockReturnValue('test diff content'); const analysis = await docService.analyzeChanges(); expect(analysis).toBeDefined(); expect(execSync).toHaveBeenCalledWith('git diff HEAD~1 HEAD'); }); it('should handle errors during analysis', async () => { (execSync as jest.Mock).mockImplementation(() => { throw new Error('Git command failed'); }); await expect(docService.analyzeChanges()).rejects.toThrow('Git command failed'); }); }); describe('createDocumentationPR', () => { it('should create a documentation PR successfully', async () => { const analysis = 'test analysis'; (execSync as jest.Mock).mockReturnValue(''); await docService.createDocumentationPR(analysis); // Verify git commands were called expect(execSync).toHaveBeenCalledWith(expect.stringContaining('git checkout -b')); expect(execSync).toHaveBeenCalledWith(expect.stringContaining('git add')); expect(execSync).toHaveBeenCalledWith(expect.stringContaining('git commit')); expect(execSync).toHaveBeenCalledWith(expect.stringContaining('git push')); }); it('should handle PR creation errors', async () => { const analysis = 'test analysis'; (execSync as jest.Mock).mockImplementation(() => { throw new Error('PR creation failed'); }); await expect(docService.createDocumentationPR(analysis)).rejects.toThrow('PR creation failed'); }); }); describe('createJiraBacklogItem', () => { it('should create a Jira ticket successfully', async () => { const analysis = 'test analysis'; await docService.createJiraBacklogItem(analysis); // Add assertions for Jira ticket creation }); it('should handle Jira ticket creation errors', async () => { const analysis = 'test analysis'; // Mock Jira client to throw error await expect(docService.createJiraBacklogItem(analysis)).rejects.toThrow(); }); }); });