From 937bbe1d6bcec867d23a653acb4b83204ce5499c Mon Sep 17 00:00:00 2001 From: Joe Danziger Date: Sun, 11 May 2025 15:23:16 -0400 Subject: [PATCH] add rules command test --- tests/unit/commands.test.js | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/unit/commands.test.js b/tests/unit/commands.test.js index 40d91e37..20e11946 100644 --- a/tests/unit/commands.test.js +++ b/tests/unit/commands.test.js @@ -1082,3 +1082,41 @@ describe('Update check', () => { expect(consoleLogSpy.mock.calls[0][0]).toContain('1.1.0'); }); }); + +// ----------------------------------------------------------------------------- +// Rules command tests (add/remove) +// ----------------------------------------------------------------------------- +describe('rules command', () => { + let program; + let mockConsoleLog; + let mockConsoleError; + let mockExit; + + beforeEach(() => { + jest.clearAllMocks(); + program = setupCLI(); + mockConsoleLog = jest.spyOn(console, 'log').mockImplementation(() => {}); + mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {}); + mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}); + }); + + test('should handle rules add command', async () => { + // Simulate: task-master rules add roo + await program.parseAsync(['rules', 'add', 'roo'], { from: 'user' }); + // Expect some log output indicating success + expect(mockConsoleLog).toHaveBeenCalledWith(expect.stringMatching(/adding rules for brand: roo/i)); + expect(mockConsoleLog).toHaveBeenCalledWith(expect.stringMatching(/completed adding rules for brand: roo/i)); + // Should not exit with error + expect(mockExit).not.toHaveBeenCalledWith(1); + }); + + test('should handle rules remove command', async () => { + // Simulate: task-master rules remove roo + await program.parseAsync(['rules', 'remove', 'roo'], { from: 'user' }); + // Expect some log output indicating removal + expect(mockConsoleLog).toHaveBeenCalledWith(expect.stringMatching(/removing rules for brand: roo/i)); + expect(mockConsoleLog).toHaveBeenCalledWith(expect.stringMatching(/completed removal for brand: roo/i)); + // Should not exit with error + expect(mockExit).not.toHaveBeenCalledWith(1); + }); +});