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' ,
@@ -38,6 +43,7 @@ describe('getBulkOperationStatus', () => {
3843 return {
3944 bulkOperation : {
4045 id : operationId ,
46+ type : 'QUERY' ,
4147 status : 'RUNNING' ,
4248 errorCode : null ,
4349 objectCount : 100 ,
@@ -60,7 +66,7 @@ describe('getBulkOperationStatus', () => {
6066 )
6167
6268 const output = mockAndCaptureOutput ( )
63- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
69+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
6470
6571 expect ( output . output ( ) ) . toContain ( 'Bulk operation succeeded:' )
6672 expect ( output . output ( ) ) . toContain ( '100 objects' )
@@ -73,9 +79,10 @@ describe('getBulkOperationStatus', () => {
7379 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'RUNNING' , objectCount : 500 } ) )
7480
7581 const output = mockAndCaptureOutput ( )
76- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
82+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
7783
78- expect ( output . info ( ) ) . toContain ( 'Bulk operation in progress...' )
84+ expect ( output . info ( ) ) . toContain ( 'Checking bulk operation status.' )
85+ expect ( output . info ( ) ) . toContain ( 'Bulk operation in progress' )
7986 expect ( output . info ( ) ) . toContain ( '500 objects' )
8087 expect ( output . info ( ) ) . toContain ( 'Started' )
8188 } )
@@ -91,7 +98,7 @@ describe('getBulkOperationStatus', () => {
9198 )
9299
93100 const output = mockAndCaptureOutput ( )
94- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
101+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
95102
96103 expect ( output . error ( ) ) . toContain ( 'Error: ACCESS_DENIED' )
97104 expect ( output . error ( ) ) . toContain ( 'Finished' )
@@ -102,7 +109,7 @@ describe('getBulkOperationStatus', () => {
102109 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( { bulkOperation : null } )
103110
104111 const output = mockAndCaptureOutput ( )
105- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
112+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
106113
107114 expect ( output . error ( ) ) . toContain ( 'Bulk operation not found.' )
108115 expect ( output . error ( ) ) . toContain ( operationId )
@@ -112,16 +119,16 @@ describe('getBulkOperationStatus', () => {
112119 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'CREATED' , objectCount : 0 } ) )
113120
114121 const output = mockAndCaptureOutput ( )
115- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
122+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
116123
117- expect ( output . info ( ) ) . toContain ( 'Starting... ' )
124+ expect ( output . info ( ) ) . toContain ( 'Starting' )
118125 } )
119126
120127 test ( 'renders info banner for canceled operation' , async ( ) => {
121128 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'CANCELED' } ) )
122129
123130 const output = mockAndCaptureOutput ( )
124- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
131+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
125132
126133 expect ( output . info ( ) ) . toContain ( 'Bulk operation canceled.' )
127134 } )
@@ -131,7 +138,7 @@ describe('getBulkOperationStatus', () => {
131138 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperation ( { status : 'RUNNING' } ) )
132139
133140 const output = mockAndCaptureOutput ( )
134- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
141+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
135142
136143 expect ( output . output ( ) ) . toContain ( 'Started' )
137144 } )
@@ -145,7 +152,7 @@ describe('getBulkOperationStatus', () => {
145152 )
146153
147154 const output = mockAndCaptureOutput ( )
148- await getBulkOperationStatus ( { storeFqdn, operationId, remoteApp} )
155+ await getBulkOperationStatus ( { organization : mockOrganization , storeFqdn, operationId, remoteApp} )
149156
150157 expect ( output . output ( ) ) . toContain ( 'Finished' )
151158 } )
@@ -194,7 +201,7 @@ describe('listBulkOperations', () => {
194201 )
195202
196203 const output = mockAndCaptureOutput ( )
197- await listBulkOperations ( { storeFqdn, remoteApp} )
204+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
198205
199206 const outputLinesWithoutTrailingWhitespace = output
200207 . output ( )
@@ -204,7 +211,17 @@ describe('listBulkOperations', () => {
204211
205212 // terminal width in test environment is quite narrow, so values in the snapshot get wrapped
206213 expect ( outputLinesWithoutTrailingWhitespace ) . toMatchInlineSnapshot ( `
207- "ID STATUS COU DATE CREATED DATE RESULTS
214+ "╭─ info ───────────────────────────────────────────────────────────────────────╮
215+ │ │
216+ │ Listing bulk operations. │
217+ │ │
218+ │ • Organization: Test Organization │
219+ │ • App: Test App │
220+ │ • Store: test-store.myshopify.com │
221+ │ │
222+ ╰──────────────────────────────────────────────────────────────────────────────╯
223+
224+ ID STATUS COU DATE CREATED DATE RESULTS
208225 T FINISHED
209226
210227 ──────────────── ────── ─── ──────────── ─────────── ───────────────────────────
@@ -222,7 +239,7 @@ describe('listBulkOperations', () => {
222239 )
223240
224241 const output = mockAndCaptureOutput ( )
225- await listBulkOperations ( { storeFqdn, remoteApp} )
242+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
226243
227244 expect ( output . output ( ) ) . toContain ( '1.2M' )
228245 expect ( output . output ( ) ) . toContain ( '5.5K' )
@@ -242,7 +259,7 @@ describe('listBulkOperations', () => {
242259 )
243260
244261 const output = mockAndCaptureOutput ( )
245- await listBulkOperations ( { storeFqdn, remoteApp} )
262+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
246263
247264 expect ( output . output ( ) ) . toContain ( 'download' )
248265 expect ( output . output ( ) ) . toContain ( 'partial.jsonl' )
@@ -259,7 +276,7 @@ describe('listBulkOperations', () => {
259276 )
260277
261278 const output = mockAndCaptureOutput ( )
262- await listBulkOperations ( { storeFqdn, remoteApp} )
279+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
263280
264281 expect ( output . output ( ) ) . toContain ( 'download' )
265282 expect ( output . output ( ) ) . toContain ( 'results.jsonl' )
@@ -269,8 +286,9 @@ describe('listBulkOperations', () => {
269286 vi . mocked ( adminRequestDoc ) . mockResolvedValue ( mockBulkOperationsList ( [ ] ) )
270287
271288 const output = mockAndCaptureOutput ( )
272- await listBulkOperations ( { storeFqdn, remoteApp} )
289+ await listBulkOperations ( { organization : mockOrganization , storeFqdn, remoteApp} )
273290
274- expect ( output . info ( ) ) . toContain ( 'no bulk operations found in the last 7 days' )
291+ expect ( output . info ( ) ) . toContain ( 'Listing bulk operations.' )
292+ expect ( output . info ( ) ) . toContain ( 'No bulk operations found in the last 7 days.' )
275293 } )
276294} )
0 commit comments