|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { AzureDevOpsBlock } from './azure_devops' |
| 6 | + |
| 7 | +const expectedToolIds = [ |
| 8 | + 'azure_devops_add_comment', |
| 9 | + 'azure_devops_create_work_item', |
| 10 | + 'azure_devops_get_build_log', |
| 11 | + 'azure_devops_get_build_timeline', |
| 12 | + 'azure_devops_get_comments', |
| 13 | + 'azure_devops_get_pipeline', |
| 14 | + 'azure_devops_get_pipeline_run', |
| 15 | + 'azure_devops_get_work_item', |
| 16 | + 'azure_devops_get_work_items_batch', |
| 17 | + 'azure_devops_get_work_items_between_builds', |
| 18 | + 'azure_devops_list_build_logs', |
| 19 | + 'azure_devops_list_builds', |
| 20 | + 'azure_devops_list_pipeline_runs', |
| 21 | + 'azure_devops_list_pipelines', |
| 22 | + 'azure_devops_query_work_items', |
| 23 | + 'azure_devops_update_work_item', |
| 24 | +] |
| 25 | + |
| 26 | +describe('AzureDevOpsBlock', () => { |
| 27 | + const block = AzureDevOpsBlock |
| 28 | + |
| 29 | + it('exposes every Azure DevOps tool through the operation dropdown and tool access list', () => { |
| 30 | + const operation = block.subBlocks.find((subBlock) => subBlock.id === 'operation') |
| 31 | + expect(operation?.type).toBe('dropdown') |
| 32 | + expect(block.tools.access.sort()).toEqual(expectedToolIds) |
| 33 | + const operationOptions = |
| 34 | + typeof operation?.options === 'function' ? operation.options() : operation?.options |
| 35 | + expect(operationOptions?.map((option) => option.id).sort()).toEqual(expectedToolIds) |
| 36 | + }) |
| 37 | + |
| 38 | + it('limits update work item state to Azure DevOps Basic process options', () => { |
| 39 | + const state = block.subBlocks.find((subBlock) => subBlock.id === 'state') |
| 40 | + expect(state?.type).toBe('dropdown') |
| 41 | + expect(state?.options).toEqual([ |
| 42 | + { label: 'To Do', id: 'To Do' }, |
| 43 | + { label: 'Doing', id: 'Doing' }, |
| 44 | + { label: 'Done', id: 'Done' }, |
| 45 | + ]) |
| 46 | + }) |
| 47 | + |
| 48 | + it('limits create work item types to the Azure DevOps Basic process options', () => { |
| 49 | + const workItemType = block.subBlocks.find((subBlock) => subBlock.id === 'workItemType') |
| 50 | + expect(workItemType?.type).toBe('dropdown') |
| 51 | + expect(workItemType?.options).toEqual([ |
| 52 | + { label: 'Issue', id: 'Issue' }, |
| 53 | + { label: 'Task', id: 'Task' }, |
| 54 | + { label: 'Epic', id: 'Epic' }, |
| 55 | + ]) |
| 56 | + expect(workItemType?.value?.()).toBe('Issue') |
| 57 | + }) |
| 58 | + |
| 59 | + it('routes every operation to the matching tool id without serialization-time coercion', () => { |
| 60 | + for (const toolId of expectedToolIds) { |
| 61 | + expect(block.tools.config.tool?.({ operation: toolId })).toBe(toolId) |
| 62 | + } |
| 63 | + }) |
| 64 | + |
| 65 | + it('maps common params and coerces numeric fields at execution time', () => { |
| 66 | + const pipelineRunParams = block.tools.config.params?.({ |
| 67 | + accessToken: 'pat-token', |
| 68 | + organization: 'mzxchandra', |
| 69 | + project: 'sim-testing', |
| 70 | + operation: 'azure_devops_get_pipeline_run', |
| 71 | + pipelineId: '42', |
| 72 | + runId: '99', |
| 73 | + }) |
| 74 | + |
| 75 | + expect(pipelineRunParams).toMatchObject({ |
| 76 | + accessToken: 'pat-token', |
| 77 | + organization: 'mzxchandra', |
| 78 | + project: 'sim-testing', |
| 79 | + pipelineId: 42, |
| 80 | + runId: 99, |
| 81 | + }) |
| 82 | + |
| 83 | + const listBuildParams = block.tools.config.params?.({ |
| 84 | + accessToken: 'pat-token', |
| 85 | + organization: 'mzxchandra', |
| 86 | + project: 'sim-testing', |
| 87 | + operation: 'azure_devops_list_builds', |
| 88 | + resultFilter: 'failed', |
| 89 | + top: '10', |
| 90 | + }) |
| 91 | + |
| 92 | + expect(listBuildParams).toMatchObject({ |
| 93 | + accessToken: 'pat-token', |
| 94 | + organization: 'mzxchandra', |
| 95 | + project: 'sim-testing', |
| 96 | + resultFilter: 'failed', |
| 97 | + top: 10, |
| 98 | + }) |
| 99 | + |
| 100 | + const getBuildLogParams = block.tools.config.params?.({ |
| 101 | + accessToken: 'pat-token', |
| 102 | + organization: 'mzxchandra', |
| 103 | + project: 'sim-testing', |
| 104 | + operation: 'azure_devops_get_build_log', |
| 105 | + buildId: '101', |
| 106 | + logId: '3', |
| 107 | + }) |
| 108 | + |
| 109 | + expect(getBuildLogParams).toMatchObject({ |
| 110 | + accessToken: 'pat-token', |
| 111 | + organization: 'mzxchandra', |
| 112 | + project: 'sim-testing', |
| 113 | + buildId: 101, |
| 114 | + logId: 3, |
| 115 | + }) |
| 116 | + |
| 117 | + const createWorkItemParams = block.tools.config.params?.({ |
| 118 | + accessToken: 'pat-token', |
| 119 | + organization: 'mzxchandra', |
| 120 | + project: 'sim-testing', |
| 121 | + operation: 'azure_devops_create_work_item', |
| 122 | + workItemType: 'Issue', |
| 123 | + title: 'Pipeline failure', |
| 124 | + priority: '2', |
| 125 | + }) |
| 126 | + |
| 127 | + expect(createWorkItemParams).toMatchObject({ |
| 128 | + accessToken: 'pat-token', |
| 129 | + organization: 'mzxchandra', |
| 130 | + project: 'sim-testing', |
| 131 | + workItemType: 'Issue', |
| 132 | + title: 'Pipeline failure', |
| 133 | + priority: 2, |
| 134 | + }) |
| 135 | + |
| 136 | + const updateWorkItemParams = block.tools.config.params?.({ |
| 137 | + accessToken: 'pat-token', |
| 138 | + organization: 'mzxchandra', |
| 139 | + project: 'sim-testing', |
| 140 | + operation: 'azure_devops_update_work_item', |
| 141 | + workItemId: '101', |
| 142 | + state: 'Doing', |
| 143 | + effort: '8', |
| 144 | + priority: '1', |
| 145 | + }) |
| 146 | + |
| 147 | + expect(updateWorkItemParams).toMatchObject({ |
| 148 | + accessToken: 'pat-token', |
| 149 | + organization: 'mzxchandra', |
| 150 | + project: 'sim-testing', |
| 151 | + workItemId: 101, |
| 152 | + state: 'Doing', |
| 153 | + effort: 8, |
| 154 | + priority: 1, |
| 155 | + }) |
| 156 | + }) |
| 157 | + |
| 158 | + it('declares downstream outputs for pipeline, build, work item, and comment operations', () => { |
| 159 | + expect(block.outputs.content).toBeDefined() |
| 160 | + expect(block.outputs.metadata).toBeDefined() |
| 161 | + }) |
| 162 | +}) |
0 commit comments