|
1 | 1 | /* eslint-env jest */ |
2 | 2 |
|
3 | | -import { getVersion, runDoctor, addProjectWithGithubOrgs, printChecklists, printChecks, printWorkflows, executeWorkflow } from '../cli-commands.js' |
| 3 | +import { getVersion, runDoctor, addProjectWithGithubOrgs, printChecklists, printChecks, printWorkflows, executeWorkflow, printBulkImportOperations } from '../cli-commands.js' |
4 | 4 | import { getPackageJson } from '../utils.js' |
5 | | -import { APIHealthResponse, APIProjectDetails, APIGithubOrgDetails, APIErrorResponse, APIChecklistItem, APICheckItem, APIWorkflowItem, APIWorkflowRunItem } from '../types.js' |
6 | | -import { mockApiHealthResponse, mockAPIProjectResponse, mockAPIGithubOrgResponse, mockAPIChecklistResponse, mockAPICheckResponse, mockAPIWorkflowResponse, mockAPIWorkflowRunResponse } from './fixtures.js' |
| 5 | +import { APIHealthResponse, APIProjectDetails, APIGithubOrgDetails, APIErrorResponse, APIChecklistItem, APICheckItem, APIWorkflowItem, APIWorkflowRunItem, APIBulkImportOperationItem } from '../types.js' |
| 6 | +import { mockApiHealthResponse, mockAPIProjectResponse, mockAPIGithubOrgResponse, mockAPIChecklistResponse, mockAPICheckResponse, mockAPIWorkflowResponse, mockAPIWorkflowRunResponse, mockAPIBulkImportOperationResponse } from './fixtures.js' |
7 | 7 | import nock from 'nock' |
8 | 8 |
|
9 | 9 | const pkg = getPackageJson() |
@@ -586,4 +586,61 @@ describe('CLI Commands', () => { |
586 | 586 | expect(result.messages).toHaveLength(1) |
587 | 587 | }) |
588 | 588 | }) |
| 589 | + |
| 590 | + describe('printBulkImportOperations', () => { |
| 591 | + let mockBulkImportOperations: APIBulkImportOperationItem[] |
| 592 | + |
| 593 | + beforeEach(() => { |
| 594 | + nock.cleanAll() |
| 595 | + mockBulkImportOperations = [...mockAPIBulkImportOperationResponse] |
| 596 | + }) |
| 597 | + |
| 598 | + it('should retrieve and format bulk import operations successfully', async () => { |
| 599 | + // Mock API call |
| 600 | + nock('http://localhost:3000') |
| 601 | + .get('/api/v1/bulk-import') |
| 602 | + .reply(200, mockBulkImportOperations) |
| 603 | + |
| 604 | + // Execute the function |
| 605 | + const result = await printBulkImportOperations() |
| 606 | + |
| 607 | + // Verify the result |
| 608 | + expect(result.success).toBe(true) |
| 609 | + expect(result.messages[0]).toBe('Bulk import operations available:') |
| 610 | + expect(result.messages[1]).toContain(mockBulkImportOperations[0].id) |
| 611 | + expect(result.messages[1]).toContain(mockBulkImportOperations[0].description) |
| 612 | + expect(result.messages).toHaveLength(2) // Header + 1 bulk import operation |
| 613 | + expect(nock.isDone()).toBe(true) // Verify all mocked endpoints were called |
| 614 | + }) |
| 615 | + |
| 616 | + it('should handle empty bulk import operations response', async () => { |
| 617 | + // Mock empty response |
| 618 | + nock('http://localhost:3000') |
| 619 | + .get('/api/v1/bulk-import') |
| 620 | + .reply(200, []) |
| 621 | + |
| 622 | + // Execute the function |
| 623 | + const result = await printBulkImportOperations() |
| 624 | + |
| 625 | + // Verify the result |
| 626 | + expect(result.success).toBe(true) |
| 627 | + expect(result.messages).toHaveLength(1) // Only the header message |
| 628 | + expect(result.messages[0]).toBe('No bulk import operations found') |
| 629 | + }) |
| 630 | + |
| 631 | + it('should handle network errors gracefully', async () => { |
| 632 | + // Mock network error |
| 633 | + nock('http://localhost:3000') |
| 634 | + .get('/api/v1/bulk-import') |
| 635 | + .replyWithError('Network error') |
| 636 | + |
| 637 | + // Execute the function |
| 638 | + const result = await printBulkImportOperations() |
| 639 | + |
| 640 | + // Verify the result |
| 641 | + expect(result.success).toBe(false) |
| 642 | + expect(result.messages[0]).toContain('❌ Failed to retrieve bulk import operation items: Network error') |
| 643 | + expect(result.messages).toHaveLength(1) |
| 644 | + }) |
| 645 | + }) |
589 | 646 | }) |
0 commit comments