@@ -113,4 +113,72 @@ describe('createWorkItem integration', () => {
113
113
expect ( result . fields [ 'System.Tags' ] ) . toContain ( 'Automated' ) ;
114
114
}
115
115
} ) ;
116
+
117
+ test ( 'should create a child work item with parent-child relationship' , async ( ) => {
118
+ // Skip if no connection is available
119
+ if ( shouldSkipIntegrationTest ( ) ) {
120
+ return ;
121
+ }
122
+
123
+ // This connection must be available if we didn't skip
124
+ if ( ! connection ) {
125
+ throw new Error (
126
+ 'Connection should be available when test is not skipped' ,
127
+ ) ;
128
+ }
129
+
130
+ // For a true integration test, use a real project
131
+ const projectName =
132
+ process . env . AZURE_DEVOPS_DEFAULT_PROJECT || 'DefaultProject' ;
133
+
134
+ // First, create a parent work item (User Story)
135
+ const parentTitle = `Parent Story ${ new Date ( ) . toISOString ( ) } ` ;
136
+ const parentOptions : CreateWorkItemOptions = {
137
+ title : parentTitle ,
138
+ description : 'This is a parent user story' ,
139
+ } ;
140
+
141
+ const parentResult = await createWorkItem (
142
+ connection ,
143
+ projectName ,
144
+ 'User Story' , // Assuming User Story type exists
145
+ parentOptions ,
146
+ ) ;
147
+
148
+ expect ( parentResult ) . toBeDefined ( ) ;
149
+ expect ( parentResult . id ) . toBeDefined ( ) ;
150
+ const parentId = parentResult . id ;
151
+
152
+ // Now create a child work item (Task) with a link to the parent
153
+ const childTitle = `Child Task ${ new Date ( ) . toISOString ( ) } ` ;
154
+ const childOptions : CreateWorkItemOptions = {
155
+ title : childTitle ,
156
+ description : 'This is a child task of a user story' ,
157
+ parentId : parentId , // Reference to parent work item
158
+ } ;
159
+
160
+ const childResult = await createWorkItem (
161
+ connection ,
162
+ projectName ,
163
+ 'Task' ,
164
+ childOptions ,
165
+ ) ;
166
+
167
+ // Assert the child work item was created
168
+ expect ( childResult ) . toBeDefined ( ) ;
169
+ expect ( childResult . id ) . toBeDefined ( ) ;
170
+
171
+ // Now verify the parent-child relationship
172
+ // We would need to fetch the relations, but for now we'll just assert
173
+ // that the response indicates a relationship was created
174
+ expect ( childResult . relations ) . toBeDefined ( ) ;
175
+
176
+ // Check that at least one relation exists that points to our parent
177
+ const parentRelation = childResult . relations ?. find (
178
+ relation =>
179
+ relation . rel === 'System.LinkTypes.Hierarchy-Reverse' &&
180
+ relation . url && relation . url . includes ( `/${ parentId } ` )
181
+ ) ;
182
+ expect ( parentRelation ) . toBeDefined ( ) ;
183
+ } ) ;
116
184
} ) ;
0 commit comments