UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

Azure DevOps reference server for the Model Context Protocol (MCP)

113 lines 5.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const feature_1 = require("./feature"); const feature_2 = require("../create-work-item/feature"); const test_helpers_1 = require("@/shared/test/test-helpers"); const shouldSkip = (0, test_helpers_1.shouldSkipIntegrationTest)(); const describeOrSkip = shouldSkip ? describe.skip : describe; describeOrSkip('updateWorkItem integration', () => { let connection; let createdWorkItemId; beforeAll(async () => { // Get a real connection using environment variables const testConnection = await (0, test_helpers_1.getTestConnection)(); if (!testConnection) { throw new Error('Connection should be available when integration tests are enabled'); } connection = testConnection; // Create a work item to be used by the update tests const projectName = process.env.AZURE_DEVOPS_DEFAULT_PROJECT || 'DefaultProject'; const uniqueTitle = `Update Test Work Item ${new Date().toISOString()}`; const options = { title: uniqueTitle, description: 'Initial description for update tests', priority: 3, }; const workItem = await (0, feature_2.createWorkItem)(connection, projectName, 'Task', options); if (!workItem?.id) { throw new Error('Failed to create work item for update tests'); } createdWorkItemId = workItem.id; }); test('should update a work item title in Azure DevOps', async () => { // Generate a unique updated title const updatedTitle = `Updated Title ${new Date().toISOString()}`; const options = { title: updatedTitle, }; // Act - make an actual API call to Azure DevOps to update the work item const result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, options); // Assert on the actual response expect(result).toBeDefined(); expect(result.id).toBe(createdWorkItemId); // Verify fields match what we updated expect(result.fields).toBeDefined(); if (result.fields) { expect(result.fields['System.Title']).toBe(updatedTitle); } }); test('should update multiple fields at once', async () => { const newDescription = 'This is an updated description from integration tests'; const newPriority = 1; const options = { description: newDescription, priority: newPriority, additionalFields: { 'System.Tags': 'UpdateTest,Integration', }, }; // Act - make an actual API call to Azure DevOps const result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, options); // Assert on the actual response expect(result).toBeDefined(); expect(result.id).toBe(createdWorkItemId); // Verify fields match what we updated expect(result.fields).toBeDefined(); if (result.fields) { expect(result.fields['System.Description']).toBe(newDescription); expect(result.fields['Microsoft.VSTS.Common.Priority']).toBe(newPriority); // Just check that tags contain both values, order may vary expect(result.fields['System.Tags']).toContain('UpdateTest'); expect(result.fields['System.Tags']).toContain('Integration'); } }); test('should throw error when updating non-existent work item', async () => { // Use a very large ID that's unlikely to exist const nonExistentId = 999999999; const options = { title: 'This should fail', }; // Act & Assert - should throw an error for non-existent work item await expect((0, feature_1.updateWorkItem)(connection, nonExistentId, options)).rejects.toThrow(/Failed to update work item|not found/); }); test('should manage tags using first-class fields (tags, tagsToAdd, tagsToRemove)', async () => { // 1. Overwrite tags let result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, { tags: ['A', 'B'], }); expect(result.fields).toBeDefined(); expect(result.fields?.['System.Tags']).toBe('A; B'); // 2. Append tags result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, { tagsToAdd: ['B', 'C', 'D'], }); expect(result.fields?.['System.Tags']).toContain('A'); expect(result.fields?.['System.Tags']).toContain('B'); expect(result.fields?.['System.Tags']).toContain('C'); expect(result.fields?.['System.Tags']).toContain('D'); // 3. Remove tags result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, { tagsToRemove: ['A', 'D', 'E'], }); expect(result.fields?.['System.Tags']).not.toContain('A'); expect(result.fields?.['System.Tags']).toContain('B'); expect(result.fields?.['System.Tags']).toContain('C'); expect(result.fields?.['System.Tags']).not.toContain('D'); // 4. Overwrite to clear result = await (0, feature_1.updateWorkItem)(connection, createdWorkItemId, { tags: [], }); expect(result.fields?.['System.Tags'] || '').toBe(''); }); }); //# sourceMappingURL=feature.spec.int.js.map