From d0cabe5c837e0db824c68da3b1633970ef5501df Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Mon, 13 Jul 2026 00:34:10 +0000 Subject: [PATCH] Add unit tests for app bulk execute command Added comprehensive unit tests for the `app bulk execute` command in `packages/app/src/cli/commands/app/bulk/execute.test.ts`. These tests verify that the command correctly parses flags and interacts with the `prepareExecuteContext` and `executeBulkOperation` services. --- .../src/cli/commands/app/bulk/execute.test.ts | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 packages/app/src/cli/commands/app/bulk/execute.test.ts diff --git a/packages/app/src/cli/commands/app/bulk/execute.test.ts b/packages/app/src/cli/commands/app/bulk/execute.test.ts new file mode 100644 index 00000000000..f8b10e2d46d --- /dev/null +++ b/packages/app/src/cli/commands/app/bulk/execute.test.ts @@ -0,0 +1,112 @@ +import BulkExecute from './execute.js' +import {executeBulkOperation} from '../../../services/bulk-operations/execute-bulk-operation.js' +import {prepareExecuteContext} from '../../../utilities/execute-command-helpers.js' +import { + testAppLinked, + testOrganization, + testOrganizationApp, + testOrganizationStore, + testProject, +} from '../../../models/app/app.test-data.js' +import {describe, expect, test, vi, beforeEach} from 'vitest' + +vi.mock('../../../services/bulk-operations/execute-bulk-operation.js') +vi.mock('../../../utilities/execute-command-helpers.js') + +describe('app bulk execute command', () => { + const app = testAppLinked() + const remoteApp = testOrganizationApp() + const organization = testOrganization() + const store = testOrganizationStore({shopDomain: 'shop.myshopify.com'}) + + beforeEach(() => { + vi.mocked(prepareExecuteContext).mockResolvedValue({ + appContextResult: { + app, + remoteApp, + developerPlatformClient: remoteApp.developerPlatformClient, + organization, + specifications: [], + project: testProject(), + activeConfig: {} as never, + }, + store, + query: 'query { shop { name } }', + }) + vi.mocked(executeBulkOperation).mockResolvedValue() + }) + + test('prepares execution context and calls executeBulkOperation', async () => { + // When + await BulkExecute.run(['--query', 'query { shop { name } }', '--store', 'shop.myshopify.com']) + + // Then + expect(prepareExecuteContext).toHaveBeenCalledWith( + expect.objectContaining({ + query: 'query { shop { name } }', + store: 'shop.myshopify.com', + }), + ) + expect(executeBulkOperation).toHaveBeenCalledWith({ + organization, + remoteApp, + store, + query: 'query { shop { name } }', + variables: undefined, + variableFile: undefined, + watch: false, + outputFile: undefined, + }) + }) + + test('calls executeBulkOperation with variables flag', async () => { + // When + await BulkExecute.run([ + '--query', + 'query { shop { name } }', + '--store', + 'shop.myshopify.com', + '--variables', + '{"key": "value"}', + '--watch', + '--output-file', + 'output.json', + ]) + + // Then + expect(executeBulkOperation).toHaveBeenCalledWith({ + organization, + remoteApp, + store, + query: 'query { shop { name } }', + variables: ['{"key": "value"}'], + variableFile: undefined, + watch: true, + outputFile: 'output.json', + }) + }) + + test('calls executeBulkOperation with variable-file flag', async () => { + // When + await BulkExecute.run([ + '--query-file', + 'query.graphql', + '--store', + 'shop.myshopify.com', + '--variable-file', + 'variables.jsonl', + ]) + + // Then + expect(executeBulkOperation).toHaveBeenCalledWith({ + organization, + remoteApp, + store, + query: 'query { shop { name } }', + variables: undefined, + variableFile: expect.stringContaining('variables.jsonl'), + watch: false, + outputFile: undefined, + }) + }) +})