@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
111 lines • 5.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const server_1 = require("../../../server");
const test_helpers_1 = require("../../../shared/test/test-helpers");
const feature_1 = require("./feature");
const auth_1 = require("../../../shared/auth");
// Skip tests if no PAT is available
const hasPat = process.env.AZURE_DEVOPS_PAT && process.env.AZURE_DEVOPS_ORG_URL;
const describeOrSkip = hasPat ? describe : describe.skip;
describeOrSkip('getAllRepositoriesTree (Integration)', () => {
let connection;
let config;
let projectId;
let orgId;
beforeAll(async () => {
if ((0, test_helpers_1.shouldSkipIntegrationTest)()) {
return;
}
// Configuration values
config = {
organizationUrl: process.env.AZURE_DEVOPS_ORG_URL || '',
authMethod: auth_1.AuthenticationMethod.PersonalAccessToken,
personalAccessToken: process.env.AZURE_DEVOPS_PAT || '',
defaultProject: process.env.AZURE_DEVOPS_DEFAULT_PROJECT || '',
};
// Use test project - should be defined in .env file
projectId =
process.env.AZURE_DEVOPS_TEST_PROJECT_ID ||
process.env.AZURE_DEVOPS_DEFAULT_PROJECT ||
'';
// Extract organization ID from URL
const url = new URL(config.organizationUrl);
const pathParts = url.pathname.split('/').filter(Boolean);
orgId = pathParts[0] || '';
// Get Azure DevOps connection
connection = await (0, server_1.getConnection)(config);
// Skip tests if no project ID is set
if (!projectId) {
console.warn('Skipping integration tests: No test project ID set');
}
}, 30000);
// Skip all tests if integration tests are disabled
beforeEach(() => {
if ((0, test_helpers_1.shouldSkipIntegrationTest)()) {
jest.resetAllMocks();
return;
}
});
it('should retrieve tree for all repositories with maximum depth (default)', async () => {
// Skip test if no project ID or if integration tests are disabled
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !projectId) {
return;
}
const result = await (0, feature_1.getAllRepositoriesTree)(connection, {
organizationId: orgId,
projectId: projectId,
// depth defaults to 0 (unlimited)
});
expect(result).toBeDefined();
expect(result.repositories).toBeDefined();
expect(Array.isArray(result.repositories)).toBe(true);
expect(result.repositories.length).toBeGreaterThan(0);
// Check that at least one repository has a tree
const repoWithTree = result.repositories.find((r) => r.tree.length > 0);
expect(repoWithTree).toBeDefined();
if (repoWithTree) {
// Verify that deep nesting is included (finding items with level > 2)
// Note: This might not always be true depending on repos, but there should be at least some nested items
const deepItems = repoWithTree.tree.filter((item) => item.level > 2);
expect(deepItems.length).toBeGreaterThan(0);
// Verify stats are correct
expect(repoWithTree.stats.directories).toBeGreaterThanOrEqual(0);
expect(repoWithTree.stats.files).toBeGreaterThan(0);
const dirCount = repoWithTree.tree.filter((item) => item.isFolder).length;
const fileCount = repoWithTree.tree.filter((item) => !item.isFolder).length;
expect(repoWithTree.stats.directories).toBe(dirCount);
expect(repoWithTree.stats.files).toBe(fileCount);
}
}, 60000); // Longer timeout because max depth can take time
it('should retrieve tree for all repositories with limited depth (depth=1)', async () => {
// Skip test if no project ID or if integration tests are disabled
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !projectId) {
return;
}
const result = await (0, feature_1.getAllRepositoriesTree)(connection, {
organizationId: orgId,
projectId: projectId,
depth: 1, // Only 1 level deep
});
expect(result).toBeDefined();
expect(result.repositories).toBeDefined();
expect(Array.isArray(result.repositories)).toBe(true);
expect(result.repositories.length).toBeGreaterThan(0);
// Check that at least one repository has a tree
const repoWithTree = result.repositories.find((r) => r.tree.length > 0);
expect(repoWithTree).toBeDefined();
if (repoWithTree) {
// Verify that only shallow nesting is included (all items should have level = 1)
const allItemsLevel1 = repoWithTree.tree.every((item) => item.level === 1);
expect(allItemsLevel1).toBe(true);
// Verify stats are correct
expect(repoWithTree.stats.directories).toBeGreaterThanOrEqual(0);
expect(repoWithTree.stats.files).toBeGreaterThanOrEqual(0);
const dirCount = repoWithTree.tree.filter((item) => item.isFolder).length;
const fileCount = repoWithTree.tree.filter((item) => !item.isFolder).length;
expect(repoWithTree.stats.directories).toBe(dirCount);
expect(repoWithTree.stats.files).toBe(fileCount);
}
}, 30000);
});
//# sourceMappingURL=feature.spec.int.js.map