@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
108 lines • 4.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const feature_1 = require("./feature");
const feature_2 = require("../list-pipelines/feature");
const test_helpers_1 = require("../../../shared/test/test-helpers");
describe('triggerPipeline integration', () => {
let connection = null;
let projectId;
let existingPipelineId = null;
beforeAll(async () => {
// Get a real connection using environment variables
connection = await (0, test_helpers_1.getTestConnection)();
// Get the project ID from environment variables, fallback to default
projectId = process.env.AZURE_DEVOPS_DEFAULT_PROJECT || 'DefaultProject';
// Skip if no connection or project is available
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !connection || !projectId) {
return;
}
// Try to get an existing pipeline ID for testing
try {
const pipelines = await (0, feature_2.listPipelines)(connection, { projectId });
if (pipelines.length > 0) {
existingPipelineId = pipelines[0].id ?? null;
}
}
catch (error) {
console.log('Could not find existing pipelines for testing:', error);
}
});
test('should trigger a pipeline run', async () => {
// Skip if no connection, project, or pipeline ID is available
if ((0, test_helpers_1.shouldSkipIntegrationTest)() ||
!connection ||
!projectId ||
!existingPipelineId) {
console.log('Skipping triggerPipeline integration test - no connection, project or existing pipeline available');
return;
}
// Arrange - prepare options for running the pipeline
const options = {
projectId,
pipelineId: existingPipelineId,
// Use previewRun mode to avoid actually triggering pipelines during tests
previewRun: true,
};
// Act - trigger the pipeline
const run = await (0, feature_1.triggerPipeline)(connection, options);
// Assert - verify the response
expect(run).toBeDefined();
// Run ID should be present
expect(run.id).toBeDefined();
expect(typeof run.id).toBe('number');
// Pipeline reference should match the pipeline we triggered
expect(run.pipeline?.id).toBe(existingPipelineId);
// URL should exist and point to the run
expect(run.url).toBeDefined();
expect(run.url).toContain('_apis/pipelines');
});
test('should trigger with custom branch', async () => {
// Skip if no connection, project, or pipeline ID is available
if ((0, test_helpers_1.shouldSkipIntegrationTest)() ||
!connection ||
!projectId ||
!existingPipelineId) {
console.log('Skipping triggerPipeline advanced test - no connection, project or existing pipeline available');
return;
}
// Arrange - prepare options with a branch
const options = {
projectId,
pipelineId: existingPipelineId,
branch: 'main', // Use the main branch
// Use previewRun mode to avoid actually triggering pipelines during tests
previewRun: true,
};
// Act - trigger the pipeline with custom options
const run = await (0, feature_1.triggerPipeline)(connection, options);
// Assert - verify the response
expect(run).toBeDefined();
expect(run.id).toBeDefined();
// Resources should include the specified branch
expect(run.resources?.repositories?.self?.refName).toBe('refs/heads/main');
});
test('should handle non-existent pipeline', async () => {
// Skip if no connection or project is available
if ((0, test_helpers_1.shouldSkipIntegrationTest)() || !connection || !projectId) {
console.log('Skipping triggerPipeline error test - no connection or project available');
return;
}
// Use a very high ID that is unlikely to exist
const nonExistentPipelineId = 999999;
try {
// Attempt to trigger a pipeline that shouldn't exist
await (0, feature_1.triggerPipeline)(connection, {
projectId,
pipelineId: nonExistentPipelineId,
});
// If we reach here without an error, we'll fail the test
fail('Expected triggerPipeline to throw an error for non-existent pipeline');
}
catch (error) {
// We expect an error, so this test passes if we get here
expect(error).toBeDefined();
// Note: the exact error type might vary depending on the API response
}
});
});
//# sourceMappingURL=feature.spec.int.js.map