@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
139 lines • 5.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const feature_1 = require("./feature");
const GitInterfaces_1 = require("azure-devops-node-api/interfaces/GitInterfaces");
describe('updatePullRequestThreadStatus', () => {
afterEach(() => {
jest.resetAllMocks();
});
test('should update pull request thread status successfully', async () => {
const mockThread = {
id: 456,
status: GitInterfaces_1.CommentThreadStatus.Fixed,
comments: [
{
id: 101,
content: 'Some comment',
commentType: GitInterfaces_1.CommentType.Text,
author: { displayName: 'User' },
},
],
threadContext: {
filePath: '/src/app.ts',
rightFileStart: { line: 10, offset: 1 },
},
};
const mockGitApi = {
updateThread: jest.fn().mockResolvedValue(mockThread),
getPullRequestById: jest.fn(),
};
const mockConnection = {
getGitApi: jest.fn().mockResolvedValue(mockGitApi),
};
const projectId = 'test-project';
const repositoryId = 'test-repo';
const pullRequestId = 123;
const threadId = 456;
const options = {
projectId,
repositoryId,
pullRequestId,
threadId,
status: 'fixed',
};
const result = await (0, feature_1.updatePullRequestThreadStatus)(mockConnection, projectId, repositoryId, pullRequestId, threadId, options);
expect(result).toEqual({
thread: {
...mockThread,
status: 'fixed',
comments: [
{
...mockThread.comments[0],
filePath: '/src/app.ts',
leftFileStart: undefined,
leftFileEnd: undefined,
rightFileStart: { line: 10, offset: 1 },
rightFileEnd: undefined,
commentType: 'text',
},
],
},
});
expect(mockConnection.getGitApi).toHaveBeenCalledTimes(1);
expect(mockGitApi.updateThread).toHaveBeenCalledTimes(1);
expect(mockGitApi.updateThread).toHaveBeenCalledWith({ status: GitInterfaces_1.CommentThreadStatus.Fixed }, repositoryId, pullRequestId, threadId, projectId);
});
test('should derive repositoryId from pullRequestId when repositoryId is omitted', async () => {
const mockThread = {
id: 456,
status: GitInterfaces_1.CommentThreadStatus.Closed,
comments: [],
};
const mockGitApi = {
getPullRequestById: jest.fn().mockResolvedValue({
repository: { id: 'derived-repo' },
}),
updateThread: jest.fn().mockResolvedValue(mockThread),
};
const mockConnection = {
getGitApi: jest.fn().mockResolvedValue(mockGitApi),
};
const projectId = 'test-project';
const pullRequestId = 123;
const threadId = 456;
const options = {
projectId,
pullRequestId,
threadId,
status: 'closed',
};
const result = await (0, feature_1.updatePullRequestThreadStatus)(mockConnection, projectId, undefined, pullRequestId, threadId, options);
expect(result.thread.status).toBe('closed');
expect(mockGitApi.getPullRequestById).toHaveBeenCalledWith(pullRequestId, projectId);
expect(mockGitApi.updateThread).toHaveBeenCalledWith({ status: GitInterfaces_1.CommentThreadStatus.Closed }, 'derived-repo', pullRequestId, threadId, projectId);
});
test('should throw error when repositoryId cannot be derived', async () => {
const mockGitApi = {
getPullRequestById: jest.fn().mockResolvedValue(null),
updateThread: jest.fn(),
};
const mockConnection = {
getGitApi: jest.fn().mockResolvedValue(mockGitApi),
};
const options = {
pullRequestId: 123,
threadId: 456,
status: 'closed',
};
await expect((0, feature_1.updatePullRequestThreadStatus)(mockConnection, undefined, undefined, 123, 456, options)).rejects.toThrow('repositoryId is required');
});
test('should throw error when status is invalid', async () => {
const mockGitApi = {
updateThread: jest.fn(),
};
const mockConnection = {
getGitApi: jest.fn().mockResolvedValue(mockGitApi),
};
const options = {
pullRequestId: 123,
threadId: 456,
status: 'invalid-status',
};
await expect((0, feature_1.updatePullRequestThreadStatus)(mockConnection, 'test-project', 'test-repo', 123, 456, options)).rejects.toThrow('Invalid status value: invalid-status');
});
test('should handle API errors correctly', async () => {
const mockGitApi = {
updateThread: jest.fn().mockRejectedValue(new Error('API Error')),
};
const mockConnection = {
getGitApi: jest.fn().mockResolvedValue(mockGitApi),
};
const options = {
pullRequestId: 123,
threadId: 456,
status: 'fixed',
};
await expect((0, feature_1.updatePullRequestThreadStatus)(mockConnection, 'test-project', 'test-repo', 123, 456, options)).rejects.toThrow('Failed to update pull request thread status: API Error');
});
});
//# sourceMappingURL=feature.spec.unit.js.map