@@ -2,22 +2,38 @@ import {executeBulkOperation} from './execute-bulk-operation.js'
22import { runBulkOperationQuery } from './run-query.js'
33import { runBulkOperationMutation } from './run-mutation.js'
44import { AppLinkedInterface } from '../../models/app/app.js'
5+ import { OrganizationApp } from '../../models/organization.js'
56import { renderSuccess , renderWarning } from '@shopify/cli-kit/node/ui'
6- import { ensureAuthenticatedAdmin } from '@shopify/cli-kit/node/session'
7+ import { ensureAuthenticatedAdminAsApp } from '@shopify/cli-kit/node/session'
78import { inTemporaryDirectory , writeFile } from '@shopify/cli-kit/node/fs'
89import { joinPath } from '@shopify/cli-kit/node/path'
910import { describe , test , expect , vi , beforeEach } from 'vitest'
1011
1112vi . mock ( './run-query.js' )
1213vi . mock ( './run-mutation.js' )
1314vi . mock ( '@shopify/cli-kit/node/ui' )
14- vi . mock ( '@shopify/cli-kit/node/session' )
15+ vi . mock ( '@shopify/cli-kit/node/session' , async ( ) => {
16+ const actual = await vi . importActual ( '@shopify/cli-kit/node/session' )
17+ return {
18+ ...actual ,
19+ ensureAuthenticatedAdminAsApp : vi . fn ( ) ,
20+ }
21+ } )
1522
1623describe ( 'executeBulkOperation' , ( ) => {
1724 const mockApp = {
1825 name : 'Test App' ,
26+ configuration : {
27+ client_id : 'test-app-client-id' ,
28+ } ,
1929 } as AppLinkedInterface
2030
31+ const mockRemoteApp = {
32+ apiKey : 'test-app-client-id' ,
33+ apiSecretKeys : [ { secret : 'test-api-secret' } ] ,
34+ title : 'Test App' ,
35+ } as OrganizationApp
36+
2137 const storeFqdn = 'test-store.myshopify.com'
2238 const mockAdminSession = { token : 'test-token' , storeFqdn}
2339
@@ -32,7 +48,7 @@ describe('executeBulkOperation', () => {
3248 }
3349
3450 beforeEach ( ( ) => {
35- vi . mocked ( ensureAuthenticatedAdmin ) . mockResolvedValue ( mockAdminSession )
51+ vi . mocked ( ensureAuthenticatedAdminAsApp ) . mockResolvedValue ( mockAdminSession )
3652 } )
3753
3854 test ( 'runs query operation when GraphQL document starts with query' , async ( ) => {
@@ -45,6 +61,7 @@ describe('executeBulkOperation', () => {
4561
4662 await executeBulkOperation ( {
4763 app : mockApp ,
64+ remoteApp : mockRemoteApp ,
4865 storeFqdn,
4966 query,
5067 } )
@@ -66,6 +83,7 @@ describe('executeBulkOperation', () => {
6683
6784 await executeBulkOperation ( {
6885 app : mockApp ,
86+ remoteApp : mockRemoteApp ,
6987 storeFqdn,
7088 query,
7189 } )
@@ -87,6 +105,7 @@ describe('executeBulkOperation', () => {
87105
88106 await executeBulkOperation ( {
89107 app : mockApp ,
108+ remoteApp : mockRemoteApp ,
90109 storeFqdn,
91110 query : mutation ,
92111 } )
@@ -110,6 +129,7 @@ describe('executeBulkOperation', () => {
110129
111130 await executeBulkOperation ( {
112131 app : mockApp ,
132+ remoteApp : mockRemoteApp ,
113133 storeFqdn,
114134 query : mutation ,
115135 variables,
@@ -131,6 +151,7 @@ describe('executeBulkOperation', () => {
131151 vi . mocked ( runBulkOperationQuery ) . mockResolvedValue ( mockResponse as any )
132152 await executeBulkOperation ( {
133153 app : mockApp ,
154+ remoteApp : mockRemoteApp ,
134155 storeFqdn,
135156 query,
136157 } )
@@ -154,6 +175,7 @@ describe('executeBulkOperation', () => {
154175
155176 await executeBulkOperation ( {
156177 app : mockApp ,
178+ remoteApp : mockRemoteApp ,
157179 storeFqdn,
158180 query,
159181 } )
@@ -172,6 +194,7 @@ describe('executeBulkOperation', () => {
172194 await expect (
173195 executeBulkOperation ( {
174196 app : mockApp ,
197+ remoteApp : mockRemoteApp ,
175198 storeFqdn,
176199 query : malformedQuery ,
177200 } ) ,
@@ -188,6 +211,7 @@ describe('executeBulkOperation', () => {
188211 await expect (
189212 executeBulkOperation ( {
190213 app : mockApp ,
214+ remoteApp : mockRemoteApp ,
191215 storeFqdn,
192216 query : multipleOperations ,
193217 } ) ,
@@ -208,6 +232,7 @@ describe('executeBulkOperation', () => {
208232 await expect (
209233 executeBulkOperation ( {
210234 app : mockApp ,
235+ remoteApp : mockRemoteApp ,
211236 storeFqdn,
212237 query : noOperations ,
213238 } ) ,
@@ -236,6 +261,7 @@ describe('executeBulkOperation', () => {
236261
237262 await executeBulkOperation ( {
238263 app : mockApp ,
264+ remoteApp : mockRemoteApp ,
239265 storeFqdn,
240266 query : mutation ,
241267 variableFile : variableFilePath ,
@@ -258,6 +284,7 @@ describe('executeBulkOperation', () => {
258284 await expect (
259285 executeBulkOperation ( {
260286 app : mockApp ,
287+ remoteApp : mockRemoteApp ,
261288 storeFqdn,
262289 query : mutation ,
263290 variableFile : nonExistentPath ,
@@ -276,6 +303,7 @@ describe('executeBulkOperation', () => {
276303 await expect (
277304 executeBulkOperation ( {
278305 app : mockApp ,
306+ remoteApp : mockRemoteApp ,
279307 storeFqdn,
280308 query,
281309 variables,
@@ -296,6 +324,7 @@ describe('executeBulkOperation', () => {
296324 await expect (
297325 executeBulkOperation ( {
298326 app : mockApp ,
327+ remoteApp : mockRemoteApp ,
299328 storeFqdn,
300329 query,
301330 variableFile : variableFilePath ,
0 commit comments