|
| 1 | +import { |
| 2 | + afterEach, |
| 3 | + beforeEach, |
| 4 | + describe, |
| 5 | + expect, |
| 6 | + type Mock, |
| 7 | + spyOn, |
| 8 | + test, |
| 9 | +} from 'bun:test'; |
| 10 | +import { deleteCommand } from './delete.ts'; |
| 11 | + |
| 12 | +// Note: These tests focus on CLI flag parsing and command structure |
| 13 | +// They do NOT test the actual Mux API integration (that's tested via E2E) |
| 14 | + |
| 15 | +describe('mux annotations delete command', () => { |
| 16 | + let exitSpy: Mock<typeof process.exit>; |
| 17 | + let consoleErrorSpy: Mock<typeof console.error>; |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + // Mock process.exit to prevent it from killing the test runner |
| 21 | + exitSpy = spyOn(process, 'exit').mockImplementation((() => { |
| 22 | + throw new Error('process.exit called'); |
| 23 | + }) as never); |
| 24 | + |
| 25 | + // Spy on console.error to capture error messages |
| 26 | + consoleErrorSpy = spyOn(console, 'error').mockImplementation(() => {}); |
| 27 | + }); |
| 28 | + |
| 29 | + afterEach(() => { |
| 30 | + exitSpy?.mockRestore(); |
| 31 | + consoleErrorSpy?.mockRestore(); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('Command metadata', () => { |
| 35 | + test('has correct command description', () => { |
| 36 | + expect(deleteCommand.getDescription()).toMatch(/annotation/i); |
| 37 | + }); |
| 38 | + |
| 39 | + test('requires annotation-id argument', () => { |
| 40 | + const args = deleteCommand.getArguments(); |
| 41 | + expect(args.length).toBeGreaterThan(0); |
| 42 | + expect(args[0].name).toBe('annotation-id'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('Optional flags', () => { |
| 47 | + test('has --force flag to skip confirmation', () => { |
| 48 | + const forceOption = deleteCommand |
| 49 | + .getOptions() |
| 50 | + .find((opt) => opt.name === 'force'); |
| 51 | + expect(forceOption).toBeDefined(); |
| 52 | + }); |
| 53 | + |
| 54 | + test('has --json flag for output formatting', () => { |
| 55 | + const jsonOption = deleteCommand |
| 56 | + .getOptions() |
| 57 | + .find((opt) => opt.name === 'json'); |
| 58 | + expect(jsonOption).toBeDefined(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('Input validation', () => { |
| 63 | + test('throws error when annotation-id is not provided', async () => { |
| 64 | + try { |
| 65 | + await deleteCommand.parse([]); |
| 66 | + } catch (_error) { |
| 67 | + // Expected to throw |
| 68 | + } |
| 69 | + expect(exitSpy).toHaveBeenCalled(); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments