11import { beforeEach , describe , expect , mock , test } from "bun:test" ;
2- import type { CreateLabelParams , Label } from "@shortcut/client" ;
2+ import type { CreateLabelParams , Label , Story } from "@shortcut/client" ;
33import type { ShortcutClientWrapper } from "@/client/shortcut" ;
44import type { CustomMcpServer } from "@/mcp/CustomMcpServer" ;
55import { LabelTools } from "./labels" ;
@@ -69,6 +69,41 @@ describe("LabelTools", () => {
6969 } as unknown as Label ,
7070 ] ;
7171
72+ const mockStories : Story [ ] = [
73+ {
74+ entity_type : "story" ,
75+ id : 123 ,
76+ name : "Story with label one" ,
77+ story_type : "feature" ,
78+ owner_ids : [ "user1" ] ,
79+ group_id : null ,
80+ epic_id : null ,
81+ iteration_id : null ,
82+ workflow_id : null ,
83+ workflow_state_id : 1 ,
84+ requested_by_id : null ,
85+ follower_ids : [ ] ,
86+ app_url : "https://app.shortcut.com/test/story/123" ,
87+ archived : false ,
88+ } as unknown as Story ,
89+ {
90+ entity_type : "story" ,
91+ id : 456 ,
92+ name : "Story with label two" ,
93+ story_type : "bug" ,
94+ owner_ids : [ "user2" ] ,
95+ group_id : null ,
96+ epic_id : null ,
97+ iteration_id : null ,
98+ workflow_id : null ,
99+ workflow_state_id : 2 ,
100+ requested_by_id : null ,
101+ follower_ids : [ ] ,
102+ app_url : "https://app.shortcut.com/test/story/456" ,
103+ archived : false ,
104+ } as unknown as Story ,
105+ ] ;
106+
72107 const createMockClient = ( methods ?: object ) =>
73108 ( {
74109 ...methods ,
@@ -86,14 +121,55 @@ describe("LabelTools", () => {
86121
87122 LabelTools . create ( mockClient , mockServer ) ;
88123
89- expect ( mockToolRead ) . toHaveBeenCalledTimes ( 1 ) ;
124+ expect ( mockToolRead ) . toHaveBeenCalledTimes ( 2 ) ;
90125 expect ( mockToolRead . mock . calls ?. [ 0 ] ?. [ 0 ] ) . toBe ( "labels-list" ) ;
126+ expect ( mockToolRead . mock . calls ?. [ 1 ] ?. [ 0 ] ) . toBe ( "labels-get-stories" ) ;
91127
92128 expect ( mockToolWrite ) . toHaveBeenCalledTimes ( 1 ) ;
93129 expect ( mockToolWrite . mock . calls ?. [ 0 ] ?. [ 0 ] ) . toBe ( "labels-create" ) ;
94130 } ) ;
95131 } ) ;
96132
133+ describe ( "getLabelStories method" , ( ) => {
134+ const listLabelStoriesMock = mock ( async ( ) => mockStories ) ;
135+
136+ beforeEach ( ( ) => {
137+ listLabelStoriesMock . mockClear ( ) ;
138+ } ) ;
139+
140+ test ( "should return formatted stories for a label" , async ( ) => {
141+ const mockClient = createMockClient ( {
142+ listLabelStories : listLabelStoriesMock ,
143+ getUserMap : mock ( async ( ) => new Map ( ) ) ,
144+ getWorkflowMap : mock ( async ( ) => new Map ( ) ) ,
145+ getTeamMap : mock ( async ( ) => new Map ( ) ) ,
146+ getMilestone : mock ( async ( ) => null ) ,
147+ getIteration : mock ( async ( ) => null ) ,
148+ getEpic : mock ( async ( ) => null ) ,
149+ getCustomFieldMap : mock ( async ( ) => new Map ( ) ) ,
150+ } ) ;
151+ const labelTools = new LabelTools ( mockClient ) ;
152+ const result = await labelTools . getLabelStories ( 42 ) ;
153+
154+ expect ( listLabelStoriesMock ) . toHaveBeenCalledWith ( 42 ) ;
155+
156+ const textContent = getTextContent ( result ) ;
157+ expect ( textContent ) . toContain ( "Result (2 stories found for label 42):" ) ;
158+ expect ( textContent ) . toContain ( '"name": "Story with label one"' ) ;
159+ expect ( textContent ) . toContain ( '"name": "Story with label two"' ) ;
160+ } ) ;
161+
162+ test ( "should return no stories found message when label has no stories" , async ( ) => {
163+ const mockClient = createMockClient ( {
164+ listLabelStories : mock ( async ( ) => [ ] ) ,
165+ } ) ;
166+ const labelTools = new LabelTools ( mockClient ) ;
167+ const result = await labelTools . getLabelStories ( 42 ) ;
168+
169+ expect ( getTextContent ( result ) ) . toBe ( "Result: No stories found for label 42." ) ;
170+ } ) ;
171+ } ) ;
172+
97173 describe ( "listLabels method" , ( ) => {
98174 const listLabelsMock = mock ( async ( ) => mockLabels ) ;
99175
0 commit comments