/**
* Onboarding Tools Tests
*/
import { jest } from '@jest/globals';
import {
devOnboardingCheck,
setCommandRunner
} from '../src/tools.js';
describe('Onboarding Tools', () => {
let mockRunner;
beforeEach(() => {
mockRunner = jest.fn();
setCommandRunner(mockRunner);
});
describe('devOnboardingCheck', () => {
test('should pass all checks when environment is fully configured', async () => {
mockRunner
.mockResolvedValueOnce({ success: true, stdout: 'git version 2.42.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'John Doe\njohn@example.com', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'gh version 2.40.0 (2024-01-15)', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Docker version 24.0.7', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('DEVELOPER ENVIRONMENT CHECK');
expect(result.content[0].text).toContain('[OK] git version');
expect(result.content[0].text).toContain('[OK] Git configured');
expect(result.content[0].text).toContain('[OK] GitHub CLI');
expect(result.content[0].text).toContain('[OK] Docker version');
expect(result.content[0].text).toContain('All checks passed');
});
test('should show failure when git is not installed', async () => {
mockRunner
.mockResolvedValueOnce({ success: false, error: 'command not found: git', stdout: '', stderr: '' })
.mockResolvedValueOnce({ success: false, error: '', stdout: '', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'gh version 2.40.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Docker version 24.0.7', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('[FAIL] Git not installed');
expect(result.content[0].text).toContain('1 critical issues');
});
test('should show warning when git is not configured', async () => {
mockRunner
.mockResolvedValueOnce({ success: true, stdout: 'git version 2.42.0', stderr: '' })
.mockResolvedValueOnce({ success: false, error: 'user.name not set', stdout: '', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'gh version 2.40.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Docker version 24.0.7', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('[WARN] Git user not configured');
expect(result.content[0].text).toContain('1 warnings');
});
test('should show warning when GitHub CLI is not installed', async () => {
mockRunner
.mockResolvedValueOnce({ success: true, stdout: 'git version 2.42.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'John Doe\njohn@example.com', stderr: '' })
.mockResolvedValueOnce({ success: false, error: 'command not found: gh', stdout: '', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Docker version 24.0.7', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('[WARN] GitHub CLI not installed');
});
test('should show failure when Docker is not installed', async () => {
mockRunner
.mockResolvedValueOnce({ success: true, stdout: 'git version 2.42.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'John Doe\njohn@example.com', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'gh version 2.40.0', stderr: '' })
.mockResolvedValueOnce({ success: false, error: 'command not found: docker', stdout: '', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('[FAIL] Docker not installed');
expect(result.content[0].text).toContain('1 critical issues');
});
test('should count multiple issues correctly', async () => {
mockRunner
.mockResolvedValueOnce({ success: false, error: 'not installed', stdout: '', stderr: '' }) // git
.mockResolvedValueOnce({ success: false, error: '', stdout: '', stderr: '' }) // git config
.mockResolvedValueOnce({ success: false, error: 'not installed', stdout: '', stderr: '' }) // gh
.mockResolvedValueOnce({ success: false, error: 'not installed', stdout: '', stderr: '' }); // docker
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('[FAIL] Git not installed');
expect(result.content[0].text).toContain('[WARN] Git user not configured');
expect(result.content[0].text).toContain('[WARN] GitHub CLI not installed');
expect(result.content[0].text).toContain('[FAIL] Docker not installed');
expect(result.content[0].text).toContain('2 critical issues');
expect(result.content[0].text).toContain('2 warnings');
});
test('should format git config with name and email', async () => {
mockRunner
.mockResolvedValueOnce({ success: true, stdout: 'git version 2.42.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Jane Developer\njane.dev@company.com', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'gh version 2.40.0', stderr: '' })
.mockResolvedValueOnce({ success: true, stdout: 'Docker version 24.0.7', stderr: '' });
const result = await devOnboardingCheck();
expect(result.content[0].text).toContain('Jane Developer / jane.dev@company.com');
});
});
});