@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
126 lines • 5.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const feature_1 = require("./feature");
const feature_2 = require("../create-pull-request/feature");
const test_helpers_1 = require("../../../shared/test/test-helpers");
describe('listPullRequests integration', () => {
let connection = null;
let testPullRequest = null;
let projectName;
let repositoryName;
// Generate unique branch name and PR title using timestamp
const timestamp = Date.now();
const randomSuffix = Math.floor(Math.random() * 1000);
const uniqueBranchName = `test-branch-${timestamp}-${randomSuffix}`;
const uniqueTitle = `Test PR ${timestamp}-${randomSuffix}`;
beforeAll(async () => {
// Get a real connection using environment variables
connection = await (0, test_helpers_1.getTestConnection)();
// Set up project and repository names from environment
projectName = process.env.AZURE_DEVOPS_DEFAULT_PROJECT || 'DefaultProject';
repositoryName = process.env.AZURE_DEVOPS_DEFAULT_REPOSITORY || '';
// Skip setup if integration tests should be skipped
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !connection) {
return;
}
});
afterAll(async () => {
// Clean up created resources if needed
if (testPullRequest &&
testPullRequest.pullRequestId &&
!(0, test_helpers_1.shouldSkipIntegrationTest)()) {
try {
// Abandon the test pull request if it was created
const gitApi = await connection?.getGitApi();
if (gitApi) {
await gitApi.updatePullRequest({
status: 2, // 2 = Abandoned
}, repositoryName, testPullRequest.pullRequestId, projectName);
}
}
catch (error) {
console.error('Error cleaning up test pull request:', error);
}
}
});
test('should list pull requests from repository', async () => {
// Skip if integration tests should be skipped
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !connection) {
console.log('Skipping test due to missing connection');
return;
}
// Skip if repository name is not defined
if (!repositoryName) {
console.log('Skipping test due to missing repository name');
return;
}
try {
// Create a branch for testing
const gitApi = await connection.getGitApi();
// Get the default branch info
const repository = await gitApi.getRepository(repositoryName, projectName);
if (!repository || !repository.defaultBranch) {
throw new Error('Cannot find repository or default branch');
}
// Get the commit to branch from
const commits = await gitApi.getCommits(repositoryName, {
itemVersion: {
versionType: 0, // commit
version: repository.defaultBranch.replace('refs/heads/', ''),
},
$top: 1,
}, projectName);
if (!commits || commits.length === 0) {
throw new Error('Cannot find commits in repository');
}
// Create a new branch
const refUpdate = {
name: `refs/heads/${uniqueBranchName}`,
oldObjectId: '0000000000000000000000000000000000000000',
newObjectId: commits[0].commitId,
};
const updateResult = await gitApi.updateRefs([refUpdate], repositoryName, projectName);
if (!updateResult ||
updateResult.length === 0 ||
!updateResult[0].success) {
throw new Error('Failed to create new branch');
}
// Create a test pull request
testPullRequest = await (0, feature_2.createPullRequest)(connection, projectName, repositoryName, {
title: uniqueTitle,
description: 'Test pull request for integration testing',
sourceRefName: `refs/heads/${uniqueBranchName}`,
targetRefName: repository.defaultBranch,
isDraft: true,
});
// List pull requests
const pullRequests = await (0, feature_1.listPullRequests)(connection, projectName, repositoryName, { projectId: projectName, repositoryId: repositoryName });
// Verify
expect(pullRequests).toBeDefined();
expect(pullRequests.value).toBeDefined();
expect(Array.isArray(pullRequests.value)).toBe(true);
expect(typeof pullRequests.count).toBe('number');
expect(typeof pullRequests.hasMoreResults).toBe('boolean');
// Find our test PR in the list
const foundPR = pullRequests.value.find((pr) => pr.pullRequestId === testPullRequest?.pullRequestId);
expect(foundPR).toBeDefined();
expect(foundPR?.title).toBe(uniqueTitle);
// Test with filters
const filteredPRs = await (0, feature_1.listPullRequests)(connection, projectName, repositoryName, {
projectId: projectName,
repositoryId: repositoryName,
status: 'active',
top: 5,
});
expect(filteredPRs).toBeDefined();
expect(filteredPRs.value).toBeDefined();
expect(Array.isArray(filteredPRs.value)).toBe(true);
expect(filteredPRs.count).toBeGreaterThanOrEqual(0);
}
catch (error) {
console.error('Test error:', error);
throw error;
}
}, 30000); // 30 second timeout for integration test
});
//# sourceMappingURL=feature.spec.int.js.map