@@ -3,6 +3,7 @@ import {runBulkOperationQuery} from './run-query.js'
33import { runBulkOperationMutation } from './run-mutation.js'
44import { watchBulkOperation } from './watch-bulk-operation.js'
55import { downloadBulkOperationResults } from './download-bulk-operation-results.js'
6+ import { validateApiVersion } from '../graphql/common.js'
67import { BulkOperationRunQueryMutation } from '../../api/graphql/bulk-operations/generated/bulk-operation-run-query.js'
78import { BulkOperationRunMutationMutation } from '../../api/graphql/bulk-operations/generated/bulk-operation-run-mutation.js'
89import { OrganizationApp } from '../../models/organization.js'
@@ -17,6 +18,13 @@ vi.mock('./run-query.js')
1718vi . mock ( './run-mutation.js' )
1819vi . mock ( './watch-bulk-operation.js' )
1920vi . mock ( './download-bulk-operation-results.js' )
21+ vi . mock ( '../graphql/common.js' , async ( ) => {
22+ const actual = await vi . importActual ( '../graphql/common.js' )
23+ return {
24+ ...actual ,
25+ validateApiVersion : vi . fn ( ) ,
26+ }
27+ } )
2028vi . mock ( '@shopify/cli-kit/node/ui' )
2129vi . mock ( '@shopify/cli-kit/node/fs' )
2230vi . mock ( '@shopify/cli-kit/node/session' , async ( ) => {
@@ -26,13 +34,6 @@ vi.mock('@shopify/cli-kit/node/session', async () => {
2634 ensureAuthenticatedAdminAsApp : vi . fn ( ) ,
2735 }
2836} )
29- vi . mock ( '@shopify/cli-kit/node/api/admin' , async ( ) => {
30- const actual = await vi . importActual ( '@shopify/cli-kit/node/api/admin' )
31- return {
32- ...actual ,
33- supportedApiVersions : vi . fn ( ( ) => Promise . resolve ( [ '2025-01' , '2025-04' , '2025-07' , '2025-10' ] ) ) ,
34- }
35- } )
3637
3738describe ( 'executeBulkOperation' , ( ) => {
3839 const mockRemoteApp = {
@@ -469,62 +470,46 @@ describe('executeBulkOperation', () => {
469470 expect ( renderSuccess ) . not . toHaveBeenCalled ( )
470471 } )
471472
472- test ( 'allows executing bulk operations against unstable ' , async ( ) => {
473+ test ( 'validates API version when provided ' , async ( ) => {
473474 const query = '{ products { edges { node { id } } } }'
475+ const version = '2025-01'
474476 const mockResponse : BulkOperationRunQueryMutation [ 'bulkOperationRunQuery' ] = {
475477 bulkOperation : createdBulkOperation ,
476478 userErrors : [ ] ,
477479 }
478480 vi . mocked ( runBulkOperationQuery ) . mockResolvedValue ( mockResponse )
481+ vi . mocked ( validateApiVersion ) . mockResolvedValue ( )
479482
480483 await executeBulkOperation ( {
481484 remoteApp : mockRemoteApp ,
482485 storeFqdn,
483486 query,
484- version : 'unstable' ,
487+ version,
485488 } )
486489
490+ expect ( validateApiVersion ) . toHaveBeenCalledWith ( mockAdminSession , version )
487491 expect ( runBulkOperationQuery ) . toHaveBeenCalledWith ( {
488492 adminSession : mockAdminSession ,
489493 query,
490- version : 'unstable' ,
494+ version,
491495 } )
492496 } )
493497
494- test ( 'allows executing bulk operations against a specific stable version ' , async ( ) => {
498+ test ( 'does not validate version when not provided ' , async ( ) => {
495499 const query = '{ products { edges { node { id } } } }'
496500 const mockResponse : BulkOperationRunQueryMutation [ 'bulkOperationRunQuery' ] = {
497501 bulkOperation : createdBulkOperation ,
498502 userErrors : [ ] ,
499503 }
500504 vi . mocked ( runBulkOperationQuery ) . mockResolvedValue ( mockResponse )
505+ vi . mocked ( validateApiVersion ) . mockClear ( )
501506
502507 await executeBulkOperation ( {
503508 remoteApp : mockRemoteApp ,
504509 storeFqdn,
505510 query,
506- version : '2025-01' ,
507- } )
508-
509- expect ( runBulkOperationQuery ) . toHaveBeenCalledWith ( {
510- adminSession : mockAdminSession ,
511- query,
512- version : '2025-01' ,
513511 } )
514- } )
515-
516- test ( 'throws error when an API version is specified but is not supported' , async ( ) => {
517- const query = '{ products { edges { node { id } } } }'
518-
519- await expect (
520- executeBulkOperation ( {
521- remoteApp : mockRemoteApp ,
522- storeFqdn,
523- query,
524- version : '2099-12' ,
525- } ) ,
526- ) . rejects . toThrow ( 'Invalid API version' )
527512
528- expect ( runBulkOperationQuery ) . not . toHaveBeenCalled ( )
513+ expect ( validateApiVersion ) . not . toHaveBeenCalled ( )
529514 } )
530515} )
0 commit comments