@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
78 lines • 3.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const feature_1 = require("./feature");
const errors_1 = require("../../../shared/errors");
describe('createPullRequest unit', () => {
// Test for required fields validation
test('should throw error when title is not provided', async () => {
// Arrange - mock connection, never used due to validation error
const mockConnection = {
getGitApi: jest.fn(),
};
// Act & Assert
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: '',
sourceRefName: 'refs/heads/feature-branch',
targetRefName: 'refs/heads/main',
})).rejects.toThrow('Title is required');
});
test('should throw error when source branch is not provided', async () => {
// Arrange - mock connection, never used due to validation error
const mockConnection = {
getGitApi: jest.fn(),
};
// Act & Assert
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: 'Test PR',
sourceRefName: '',
targetRefName: 'refs/heads/main',
})).rejects.toThrow('Source branch is required');
});
test('should throw error when target branch is not provided', async () => {
// Arrange - mock connection, never used due to validation error
const mockConnection = {
getGitApi: jest.fn(),
};
// Act & Assert
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: 'Test PR',
sourceRefName: 'refs/heads/feature-branch',
targetRefName: '',
})).rejects.toThrow('Target branch is required');
});
// Test for error propagation
test('should propagate custom errors when thrown internally', async () => {
// Arrange
const mockConnection = {
getGitApi: jest.fn().mockImplementation(() => {
throw new errors_1.AzureDevOpsError('Custom error');
}),
};
// Act & Assert
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: 'Test PR',
sourceRefName: 'refs/heads/feature-branch',
targetRefName: 'refs/heads/main',
})).rejects.toThrow(errors_1.AzureDevOpsError);
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: 'Test PR',
sourceRefName: 'refs/heads/feature-branch',
targetRefName: 'refs/heads/main',
})).rejects.toThrow('Custom error');
});
test('should wrap unexpected errors in a friendly error message', async () => {
// Arrange
const mockConnection = {
getGitApi: jest.fn().mockImplementation(() => {
throw new Error('Unexpected error');
}),
};
// Act & Assert
await expect((0, feature_1.createPullRequest)(mockConnection, 'TestProject', 'TestRepo', {
title: 'Test PR',
sourceRefName: 'refs/heads/feature-branch',
targetRefName: 'refs/heads/main',
})).rejects.toThrow('Failed to create pull request: Unexpected error');
});
});
//# sourceMappingURL=feature.spec.unit.js.map