@@ -126,113 +126,112 @@ describe('repository', () => {
126126 */
127127 describe ( 'workflow operations' , ( ) => {
128128 beforeEach ( ( ) => {
129- // Mock the octokit requests
130- repository . octokit . request = jest . fn ( )
129+ // Mock the octokit GraphQL client
131130 repository . octokit . graphql = jest . fn ( )
132131 } )
133132
134133 test ( 'should fetch workflows for repository' , async ( ) => {
135- const mockGraphQLResponse = {
136- data : {
137- data : {
138- repository : {
139- object : {
140- entries : [
141- {
142- name : 'ci.yml' ,
143- path : '.github/workflows/ci.yml' ,
144- language : { name : 'YAML' } ,
145- object : {
146- text : 'name: CI\non: push' ,
147- isTruncated : false ,
148- } ,
149- } ,
150- {
151- name : 'release.yml' ,
152- path : '.github/workflows/release.yml' ,
153- language : { name : 'YAML' } ,
154- object : {
155- text : 'name: Release\non: release' ,
156- isTruncated : false ,
157- } ,
158- } ,
159- ] ,
134+ repository . octokit . graphql . mockResolvedValueOnce ( {
135+ repository : {
136+ object : {
137+ entries : [
138+ {
139+ name : 'ci.yml' ,
140+ path : '.github/workflows/ci.yml' ,
141+ language : { name : 'YAML' } ,
142+ object : { text : 'name: CI\non: push' , isTruncated : false , node_id : '1' } ,
160143 } ,
161- } ,
144+ {
145+ name : 'release.yml' ,
146+ path : '.github/workflows/release.yml' ,
147+ language : { name : 'YAML' } ,
148+ object : { text : 'name: Release\non: release' , isTruncated : false , node_id : '2' } ,
149+ } ,
150+ ] ,
162151 } ,
163152 } ,
164- }
153+ } )
165154
166- repository . octokit . request . mockResolvedValue ( mockGraphQLResponse )
155+ // Mock the REST workflow detail & runs requests invoked by Workflow#getWorkflow
156+ repository . octokit . request = jest
157+ . fn ( )
158+ // First workflow detail
159+ . mockResolvedValueOnce ( {
160+ data : {
161+ id : 101 ,
162+ node_id : 'W_flow_101' ,
163+ name : 'CI' ,
164+ path : '.github/workflows/ci.yml' ,
165+ state : 'active' ,
166+ created_at : '2024-01-01T00:00:00Z' ,
167+ updated_at : '2024-01-02T00:00:00Z' ,
168+ } ,
169+ } )
170+ // First workflow runs (only most recent run needed)
171+ . mockResolvedValueOnce ( {
172+ data : {
173+ workflow_runs : [ { updated_at : '2024-01-03T00:00:00Z' } ] ,
174+ } ,
175+ } )
176+ // Second workflow detail
177+ . mockResolvedValueOnce ( {
178+ data : {
179+ id : 202 ,
180+ node_id : 'W_flow_202' ,
181+ name : 'Release' ,
182+ path : '.github/workflows/release.yml' ,
183+ state : 'active' ,
184+ created_at : '2024-02-01T00:00:00Z' ,
185+ updated_at : '2024-02-02T00:00:00Z' ,
186+ } ,
187+ } )
188+ // Second workflow runs
189+ . mockResolvedValueOnce ( {
190+ data : {
191+ workflow_runs : [ { updated_at : '2024-02-03T00:00:00Z' } ] ,
192+ } ,
193+ } )
167194
168195 const workflows = await repository . getWorkflows ( 'mona' , 'sample-repo' )
169196
170197 expect ( Array . isArray ( workflows ) ) . toBe ( true )
171- // Since the actual implementation will depend on Workflow constructor,
172- // we just verify that the method runs without error
173- expect ( workflows ) . toBeDefined ( )
198+ expect ( workflows ) . toHaveLength ( 2 )
174199 } )
175200
176201 test ( 'should handle repositories without workflows' , async ( ) => {
177- const mockGraphQLResponse = {
178- data : {
179- data : {
180- repository : {
181- object : null ,
182- } ,
183- } ,
184- } ,
185- }
186-
187- repository . octokit . request . mockResolvedValueOnce ( mockGraphQLResponse )
202+ repository . octokit . graphql . mockResolvedValueOnce ( {
203+ repository : { object : null } ,
204+ } )
188205
189206 const workflows = await repository . getWorkflows ( 'mona' , 'sample-repo' )
190-
191207 expect ( Array . isArray ( workflows ) ) . toBe ( true )
192208 expect ( workflows ) . toHaveLength ( 0 )
193209 } )
194210
195211 test ( 'should handle empty workflow directory' , async ( ) => {
196- const mockGraphQLResponse = {
197- data : {
198- data : {
199- repository : {
200- object : {
201- entries : [ ] ,
202- } ,
203- } ,
204- } ,
205- } ,
206- }
207-
208- repository . octokit . request . mockResolvedValueOnce ( mockGraphQLResponse )
212+ repository . octokit . graphql . mockResolvedValueOnce ( {
213+ repository : { object : { entries : [ ] } } ,
214+ } )
209215
210216 const workflows = await repository . getWorkflows ( 'mona' , 'sample-repo' )
211-
212217 expect ( Array . isArray ( workflows ) ) . toBe ( true )
213218 expect ( workflows ) . toHaveLength ( 0 )
214219 } )
215220
216221 test ( 'should fetch repository metadata' , async ( ) => {
217- const mockRepoData = {
218- data : {
219- data : {
220- repository : {
221- nwo : 'mona/sample-repo' ,
222- owner : { login : 'mona' } ,
223- name : 'sample-repo' ,
224- id : 123 ,
225- node_id : 'MDEwOlJlcG9zaXRvcnkx' ,
226- visibility : 'PUBLIC' ,
227- isArchived : false ,
228- isFork : false ,
229- defaultBranchRef : { name : 'main' } ,
230- } ,
231- } ,
222+ repository . octokit . graphql . mockResolvedValueOnce ( {
223+ repository : {
224+ nwo : 'mona/sample-repo' ,
225+ owner : { login : 'mona' } ,
226+ name : 'sample-repo' ,
227+ id : 123 ,
228+ node_id : 'MDEwOlJlcG9zaXRvcnkx' ,
229+ visibility : 'PUBLIC' ,
230+ isArchived : false ,
231+ isFork : false ,
232+ defaultBranchRef : { name : 'main' } ,
232233 } ,
233- }
234-
235- repository . octokit . request . mockResolvedValueOnce ( mockRepoData )
234+ } )
236235
237236 const result = await repository . getRepo ( 'mona/sample-repo' )
238237
@@ -242,6 +241,7 @@ describe('repository', () => {
242241 expect ( result . visibility ) . toBe ( 'PUBLIC' )
243242 expect ( result . isArchived ) . toBe ( false )
244243 expect ( result . isFork ) . toBe ( false )
244+ expect ( result . branch ) . toBe ( 'main' )
245245 } )
246246
247247 test ( 'should handle API errors when fetching workflows' , async ( ) => {
@@ -255,7 +255,7 @@ describe('repository', () => {
255255 } ,
256256 }
257257
258- repository . octokit . request . mockResolvedValueOnce ( mockGraphQLResponse )
258+ repository . octokit . graphql . mockResolvedValueOnce ( mockGraphQLResponse )
259259
260260 const workflows = await repository . getWorkflows ( 'mona' , 'sample-repo' )
261261 expect ( Array . isArray ( workflows ) ) . toBe ( true )
0 commit comments