-
Notifications
You must be signed in to change notification settings - Fork 276
AssignedTo transformation for get work items in batch #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
149bd6a
AssignedTo transformation for get work items in batch
danhellem ed6d36f
Fix test
danhellem c9b82c1
Merge branch 'main' into users/danhellem/get-by-ids-assigned-to-1
danhellem 7a10e2d
Merge branch 'main' into users/danhellem/get-by-ids-assigned-to-1
danhellem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,13 +285,224 @@ describe("configureWorkItemTools", () => { | |
expect(mockWorkItemTrackingApi.getWorkItemsBatch).toHaveBeenCalledWith( | ||
{ | ||
ids: params.ids, | ||
fields: ["System.Id", "System.WorkItemType", "System.Title", "System.State", "System.Parent", "System.Tags", "Microsoft.VSTS.Common.StackRank"], | ||
fields: ["System.Id", "System.WorkItemType", "System.Title", "System.State", "System.Parent", "System.Tags", "Microsoft.VSTS.Common.StackRank", "System.AssignedTo"], | ||
}, | ||
params.project | ||
); | ||
|
||
expect(result.content[0].text).toBe(JSON.stringify([_mockWorkItems], null, 2)); | ||
}); | ||
|
||
it("should transform System.AssignedTo object to formatted string", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
// Mock work items with System.AssignedTo as objects | ||
const mockWorkItemsWithAssignedTo = [ | ||
{ | ||
id: 297, | ||
fields: { | ||
"System.Id": 297, | ||
"System.WorkItemType": "Bug", | ||
"System.Title": "Test Bug", | ||
"System.AssignedTo": { | ||
displayName: "John Doe", | ||
uniqueName: "[email protected]", | ||
id: "12345", | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 298, | ||
fields: { | ||
"System.Id": 298, | ||
"System.WorkItemType": "User Story", | ||
"System.Title": "Test Story", | ||
"System.AssignedTo": { | ||
displayName: "Jane Smith", | ||
uniqueName: "[email protected]", | ||
id: "67890", | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(mockWorkItemsWithAssignedTo); | ||
|
||
const params = { | ||
ids: [297, 298], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
// Parse the returned JSON to verify transformation | ||
const resultData = JSON.parse(result.content[0].text); | ||
|
||
expect(resultData[0].fields["System.AssignedTo"]).toBe("John Doe <[email protected]>"); | ||
expect(resultData[1].fields["System.AssignedTo"]).toBe("Jane Smith <[email protected]>"); | ||
}); | ||
|
||
it("should handle System.AssignedTo with only displayName", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockWorkItemsWithPartialAssignedTo = [ | ||
{ | ||
id: 297, | ||
fields: { | ||
"System.Id": 297, | ||
"System.WorkItemType": "Bug", | ||
"System.Title": "Test Bug", | ||
"System.AssignedTo": { | ||
displayName: "John Doe", | ||
id: "12345", | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(mockWorkItemsWithPartialAssignedTo); | ||
|
||
const params = { | ||
ids: [297], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
const resultData = JSON.parse(result.content[0].text); | ||
expect(resultData[0].fields["System.AssignedTo"]).toBe("John Doe <>"); | ||
}); | ||
|
||
it("should handle System.AssignedTo with only uniqueName", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockWorkItemsWithPartialAssignedTo = [ | ||
{ | ||
id: 297, | ||
fields: { | ||
"System.Id": 297, | ||
"System.WorkItemType": "Bug", | ||
"System.Title": "Test Bug", | ||
"System.AssignedTo": { | ||
uniqueName: "[email protected]", | ||
id: "12345", | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(mockWorkItemsWithPartialAssignedTo); | ||
|
||
const params = { | ||
ids: [297], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
const resultData = JSON.parse(result.content[0].text); | ||
expect(resultData[0].fields["System.AssignedTo"]).toBe("<[email protected]>"); | ||
}); | ||
|
||
it("should not transform System.AssignedTo if it's not an object", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockWorkItemsWithStringAssignedTo = [ | ||
{ | ||
id: 297, | ||
fields: { | ||
"System.Id": 297, | ||
"System.WorkItemType": "Bug", | ||
"System.Title": "Test Bug", | ||
"System.AssignedTo": "Already a string", | ||
}, | ||
}, | ||
]; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(mockWorkItemsWithStringAssignedTo); | ||
|
||
const params = { | ||
ids: [297], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
const resultData = JSON.parse(result.content[0].text); | ||
expect(resultData[0].fields["System.AssignedTo"]).toBe("Already a string"); | ||
}); | ||
|
||
it("should handle work items without System.AssignedTo field", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
const mockWorkItemsWithoutAssignedTo = [ | ||
{ | ||
id: 297, | ||
fields: { | ||
"System.Id": 297, | ||
"System.WorkItemType": "Bug", | ||
"System.Title": "Test Bug", | ||
}, | ||
}, | ||
]; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(mockWorkItemsWithoutAssignedTo); | ||
|
||
const params = { | ||
ids: [297], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
const resultData = JSON.parse(result.content[0].text); | ||
expect(resultData[0].fields["System.AssignedTo"]).toBeUndefined(); | ||
}); | ||
|
||
it("should handle null or undefined workitems response", async () => { | ||
configureWorkItemTools(server, tokenProvider, connectionProvider, userAgentProvider); | ||
|
||
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wit_get_work_items_batch_by_ids"); | ||
|
||
if (!call) throw new Error("wit_get_work_items_batch_by_ids tool not registered"); | ||
const [, , , handler] = call; | ||
|
||
(mockWorkItemTrackingApi.getWorkItemsBatch as jest.Mock).mockResolvedValue(null); | ||
|
||
const params = { | ||
ids: [297], | ||
project: "Contoso", | ||
}; | ||
|
||
const result = await handler(params); | ||
|
||
expect(result.content[0].text).toBe(JSON.stringify(null, null, 2)); | ||
}); | ||
}); | ||
|
||
describe("get_work_item tool", () => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.