diff --git a/apps/frontend/src/main/ipc-handlers/github/__tests__/oauth-handlers.spec.ts b/apps/frontend/src/main/ipc-handlers/github/__tests__/oauth-handlers.spec.ts index 48b8c255..61610667 100644 --- a/apps/frontend/src/main/ipc-handlers/github/__tests__/oauth-handlers.spec.ts +++ b/apps/frontend/src/main/ipc-handlers/github/__tests__/oauth-handlers.spec.ts @@ -72,6 +72,16 @@ vi.mock('@electron-toolkit/utils', () => ({ } })); +// Mock env-utils +const mockFindExecutable = vi.fn(); +const mockGetAugmentedEnv = vi.fn(); + +vi.mock('../../../env-utils', () => ({ + findExecutable: mockFindExecutable, + getAugmentedEnv: mockGetAugmentedEnv, + isCommandAvailable: vi.fn((cmd: string) => mockFindExecutable(cmd) !== null) +})); + // Create mock process for spawn function createMockProcess(): EventEmitter & { stdout: EventEmitter | null; @@ -100,6 +110,10 @@ describe('GitHub OAuth Handlers', () => { vi.clearAllMocks(); vi.resetModules(); + // Set up default env-utils mocks + mockGetAugmentedEnv.mockReturnValue(process.env as Record); + mockFindExecutable.mockReturnValue(null); // Default: executable not found + // Get mocked ipcMain const electron = await import('electron'); ipcMain = electron.ipcMain as unknown as typeof ipcMain; @@ -423,6 +437,10 @@ describe('GitHub OAuth Handlers', () => { describe('gh CLI Check Handler', () => { it('should return installed: true when gh CLI is found', async () => { + // Mock findExecutable to return gh path + mockFindExecutable.mockReturnValue('/usr/local/bin/gh'); + + // Mock execFileSync for version check mockExecFileSync.mockImplementation((cmd: string, args?: string[]) => { if (args && args[0] === '--version') { return 'gh version 2.65.0 (2024-01-15)\n'; @@ -442,9 +460,8 @@ describe('GitHub OAuth Handlers', () => { }); it('should return installed: false when gh CLI is not found', async () => { - mockExecFileSync.mockImplementation(() => { - throw new Error('Command not found'); - }); + // Mock findExecutable to return null (not found) + mockFindExecutable.mockReturnValue(null); const { registerCheckGhCli } = await import('../oauth-handlers'); registerCheckGhCli();