11import { getBulkOperationStatus , listBulkOperations } from './bulk-operation-status.js'
22import { GetBulkOperationByIdQuery } from '../../api/graphql/bulk-operations/generated/get-bulk-operation-by-id.js'
3- import { OrganizationApp } from '../../models/organization.js'
3+ import { OrganizationApp , Organization , OrganizationSource } from '../../models/organization.js'
44import { ListBulkOperationsQuery } from '../../api/graphql/bulk-operations/generated/list-bulk-operations.js'
55import { afterEach , beforeEach , describe , expect , test , vi } from 'vitest'
66import { ensureAuthenticatedAdminAsApp } from '@shopify/cli-kit/node/session'
@@ -12,6 +12,11 @@ vi.mock('@shopify/cli-kit/node/api/admin')
1212
1313const storeFqdn = 'test-store.myshopify.com'
1414const operationId = 'gid://shopify/BulkOperation/123'
15+ const mockOrganization : Organization = {
16+ id : 'test-org-id' ,
17+ businessName : 'Test Organization' ,
18+ source : OrganizationSource . BusinessPlatform ,
19+ }
1520const remoteApp = {
1621 id : '123' ,
1722 title : 'Test App' ,
@@ -61,7 +66,7 @@ describe('getBulkOperationStatus', () => {
6166 )
6267
6368 const output = mockAndCaptureOutput ( )
64- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
69+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
6570
6671 expect ( output . output ( ) ) . toContain ( 'Bulk operation succeeded:' )
6772 expect ( output . output ( ) ) . toContain ( '100 objects' )
@@ -74,10 +79,11 @@ describe('getBulkOperationStatus', () => {
7479 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'RUNNING' , objectCount : 500 } ) )
7580
7681 const output = mockAndCaptureOutput ( )
77- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
82+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
7883
84+ expect ( output . info ( ) ) . toContain ( 'Checking bulk operation status.' )
7985 expect ( output . info ( ) ) . toContain ( 'Bulk operation in progress' )
80- expect ( output . info ( ) ) . toContain ( '500 objects read ' )
86+ expect ( output . info ( ) ) . toContain ( '500 objects' )
8187 expect ( output . info ( ) ) . toContain ( 'Started' )
8288 } )
8389
@@ -92,7 +98,7 @@ describe('getBulkOperationStatus', () => {
9298 )
9399
94100 const output = mockAndCaptureOutput ( )
95- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
101+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
96102
97103 expect ( output . error ( ) ) . toContain ( 'Error: ACCESS_DENIED' )
98104 expect ( output . error ( ) ) . toContain ( 'Finished' )
@@ -103,7 +109,7 @@ describe('getBulkOperationStatus', () => {
103109 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( { bulkOperation : null } )
104110
105111 const output = mockAndCaptureOutput ( )
106- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
112+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
107113
108114 expect ( output . error ( ) ) . toContain ( 'Bulk operation not found.' )
109115 expect ( output . error ( ) ) . toContain ( operationId )
@@ -113,7 +119,7 @@ describe('getBulkOperationStatus', () => {
113119 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'CREATED' , objectCount : 0 } ) )
114120
115121 const output = mockAndCaptureOutput ( )
116- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
122+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
117123
118124 expect ( output . info ( ) ) . toContain ( 'Starting' )
119125 } )
@@ -122,7 +128,7 @@ describe('getBulkOperationStatus', () => {
122128 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'CANCELED' } ) )
123129
124130 const output = mockAndCaptureOutput ( )
125- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
131+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
126132
127133 expect ( output . info ( ) ) . toContain ( 'Bulk operation canceled.' )
128134 } )
@@ -132,7 +138,7 @@ describe('getBulkOperationStatus', () => {
132138 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'RUNNING' } ) )
133139
134140 const output = mockAndCaptureOutput ( )
135- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
141+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
136142
137143 expect ( output . output ( ) ) . toContain ( 'Started' )
138144 } )
@@ -146,7 +152,7 @@ describe('getBulkOperationStatus', () => {
146152 )
147153
148154 const output = mockAndCaptureOutput ( )
149- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
155+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
150156
151157 expect ( output . output ( ) ) . toContain ( 'Finished' )
152158 } )
@@ -196,7 +202,7 @@ describe('listBulkOperations', () => {
196202 )
197203
198204 const output = mockAndCaptureOutput ( )
199- await listBulkOperations ( { storeFqdn, remoteApp} )
205+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
200206
201207 const outputLinesWithoutTrailingWhitespace = output
202208 . output ( )
@@ -206,7 +212,17 @@ describe('listBulkOperations', () => {
206212
207213 // terminal width in test environment is quite narrow, so values in the snapshot get wrapped
208214 expect ( outputLinesWithoutTrailingWhitespace ) . toMatchInlineSnapshot ( `
209- "ID STATUS COU DATE CREATED DATE RESULTS
215+ "╭─ info ───────────────────────────────────────────────────────────────────────╮
216+ │ │
217+ │ Listing bulk operations. │
218+ │ │
219+ │ • Organization: Test Organization │
220+ │ • App: Test App │
221+ │ • Store: test-store.myshopify.com │
222+ │ │
223+ ╰──────────────────────────────────────────────────────────────────────────────╯
224+
225+ ID STATUS COU DATE CREATED DATE RESULTS
210226 T FINISHED
211227
212228 ──────────────── ────── ─── ──────────── ─────────── ───────────────────────────
@@ -224,7 +240,7 @@ describe('listBulkOperations', () => {
224240 )
225241
226242 const output = mockAndCaptureOutput ( )
227- await listBulkOperations ( { storeFqdn, remoteApp} )
243+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
228244
229245 expect ( output . output ( ) ) . toContain ( '1.2M' )
230246 expect ( output . output ( ) ) . toContain ( '5.5K' )
@@ -244,7 +260,7 @@ describe('listBulkOperations', () => {
244260 )
245261
246262 const output = mockAndCaptureOutput ( )
247- await listBulkOperations ( { storeFqdn, remoteApp} )
263+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
248264
249265 expect ( output . output ( ) ) . toContain ( 'download' )
250266 expect ( output . output ( ) ) . toContain ( 'partial.jsonl' )
@@ -261,7 +277,7 @@ describe('listBulkOperations', () => {
261277 )
262278
263279 const output = mockAndCaptureOutput ( )
264- await listBulkOperations ( { storeFqdn, remoteApp} )
280+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
265281
266282 expect ( output . output ( ) ) . toContain ( 'download' )
267283 expect ( output . output ( ) ) . toContain ( 'results.jsonl' )
@@ -271,8 +287,9 @@ describe('listBulkOperations', () => {
271287 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperationsList ( [ ] ) )
272288
273289 const output = mockAndCaptureOutput ( )
274- await listBulkOperations ( { storeFqdn, remoteApp} )
290+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
275291
276- expect ( output . info ( ) ) . toContain ( 'no bulk operations found in the last 7 days' )
292+ expect ( output . info ( ) ) . toContain ( 'Listing bulk operations.' )
293+ expect ( output . info ( ) ) . toContain ( 'No bulk operations found in the last 7 days.' )
277294 } )
278295} )
0 commit comments