You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixing issue with casing on operations wit_update_work_item rejects… (#326)
This pull request refactors the handling of work item update operations
in `src/tools/workitems.ts` and enhances the corresponding test coverage
in `test/src/tools/workitems.test.ts`. Key changes include simplifying
the transformation of operation strings, removing redundant code, and
adding tests for edge cases like API failures, operation
transformations, and Markdown formatting.
### Refactoring and simplification:
* Removed the `operationToApiString` utility function and replaced it
with an inline transformation using `zod` schemas to convert operation
strings to lowercase and validate them against allowed values (`add`,
`replace`, `remove`) (`src/tools/workitems.ts`,
[[1]](diffhunk://#diff-86312c74c8d340f1b252bb6a34ae3d610c400cf9151d45223ec54d2d2ab2b0c9L9-L21)
[[2]](diffhunk://#diff-86312c74c8d340f1b252bb6a34ae3d610c400cf9151d45223ec54d2d2ab2b0c9L466-R461).
* Simplified the mapping of update operations by directly using the
transformed `op` values instead of calling the removed utility function
(`src/tools/workitems.ts`,
[src/tools/workitems.tsL480-R475](diffhunk://#diff-86312c74c8d340f1b252bb6a34ae3d610c400cf9151d45223ec54d2d2ab2b0c9L480-R475)).
### Enhanced test coverage:
* Added a test case to ensure proper error handling when the API fetch
call fails, verifying that an appropriate error message is thrown
(`test/src/tools/workitems.test.ts`,
[test/src/tools/workitems.test.tsR430-R456](diffhunk://#diff-81b8c1c7196cc4eba4c6b2a30eaec7c3101f72c5a88803d07b942b71e3404b9dR430-R456)).
* Extended tests to validate the transformation of uppercase operation
strings (e.g., `Add`, `Replace`) to lowercase and their correct usage in
API calls (`test/src/tools/workitems.test.ts`,
[test/src/tools/workitems.test.tsL608-R653](diffhunk://#diff-81b8c1c7196cc4eba4c6b2a30eaec7c3101f72c5a88803d07b942b71e3404b9dL608-R653)).
* Introduced a test to verify that updates are grouped by work item ID
when batching API requests (`test/src/tools/workitems.test.ts`,
[test/src/tools/workitems.test.tsR975-R1060](diffhunk://#diff-81b8c1c7196cc4eba4c6b2a30eaec7c3101f72c5a88803d07b942b71e3404b9dR975-R1060)).
* Added a test to ensure that long text fields are correctly formatted
as Markdown when specified, including verifying the addition of a
`multilineFieldsFormat` entry in the API request body
(`test/src/tools/workitems.test.ts`,
[test/src/tools/workitems.test.tsR975-R1060](diffhunk://#diff-81b8c1c7196cc4eba4c6b2a30eaec7c3101f72c5a88803d07b942b71e3404b9dR975-R1060)).
Fixes#323
## GitHub issue number #323
## **Associated Risks**
No risks
## ✅ **PR Checklist**
- [x] **I have read the [contribution
guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CONTRIBUTING.md)**
- [x] **I have read the [code of conduct
guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CODE_OF_CONDUCT.md)**
- [x] Title of the pull request is clear and informative.
- [x] 👌 Code hygiene
- [x] 🔭 Telemetry added, updated, or N/A
- [x] 📄 Documentation added, updated, or N/A
- [x] 🛡️ Automated tests added, or N/A
## 🧪 **How did you test it?**
Updated auto tests. Verified the tools works manually and updated cases
on operations to account for uppper, lower, and combo
op: z.enum(["Add","Replace","Remove"]).default("Add").describe("The operation to perform on the field."),
456
+
op: z
457
+
.string()
458
+
.transform((val)=>val.toLowerCase())
459
+
.pipe(z.enum(["add","replace","remove"]))
460
+
.default("add")
461
+
.describe("The operation to perform on the field."),
467
462
path: z.string().describe("The path of the field to update, e.g., '/fields/System.Title'."),
468
463
value: z.string().describe("The new value for the field. This is required for 'Add' and 'Replace' operations, and should be omitted for 'Remove' operations."),
0 commit comments