diff --git a/packages/cli/src/cli/commands/doctor-release/theme/index.test.ts b/packages/cli/src/cli/commands/doctor-release/theme/index.test.ts new file mode 100644 index 0000000000..71cb3012c4 --- /dev/null +++ b/packages/cli/src/cli/commands/doctor-release/theme/index.test.ts @@ -0,0 +1,47 @@ +import DoctorReleaseTheme from './index.js' +import {runThemeDoctor} from '../../../services/doctor-release/theme/runner.js' +import {renderConfirmationPrompt} from '@shopify/cli-kit/node/ui' +import {afterEach, expect, test, vi} from 'vitest' + +vi.mock('@shopify/cli-kit/node/ui') +vi.mock('../../../services/doctor-release/theme/runner.js') + +afterEach(() => { + vi.unstubAllEnvs() +}) + +test('does not run theme doctor when user cancels', async () => { + // Given + vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1') + vi.mocked(renderConfirmationPrompt).mockResolvedValue(false) + + // When + await DoctorReleaseTheme.run(['--environment', 'test']) + + // Then + expect(runThemeDoctor).not.toHaveBeenCalled() +}) + +test('runs theme doctor when user confirms', async () => { + // Given + vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1') + vi.mocked(renderConfirmationPrompt).mockResolvedValue(true) + vi.mocked(runThemeDoctor).mockResolvedValue([]) + + // When + await DoctorReleaseTheme.run(['--environment', 'test']) + + // Then + expect(runThemeDoctor).toHaveBeenCalled() +}) + +test('does not run theme doctor when environment variable is not set', async () => { + // Given - no SHOPIFY_CLI_DOCTOR env var set + + // When + await DoctorReleaseTheme.run(['--environment', 'test']) + + // Then - neither prompt nor doctor should be called + expect(renderConfirmationPrompt).not.toHaveBeenCalled() + expect(runThemeDoctor).not.toHaveBeenCalled() +}) diff --git a/packages/cli/src/cli/commands/doctor-release/theme/index.ts b/packages/cli/src/cli/commands/doctor-release/theme/index.ts index 026a1f0eea..576bd325fa 100644 --- a/packages/cli/src/cli/commands/doctor-release/theme/index.ts +++ b/packages/cli/src/cli/commands/doctor-release/theme/index.ts @@ -4,6 +4,7 @@ import {globalFlags} from '@shopify/cli-kit/node/cli' import {Flags} from '@oclif/core' import {resolvePath, cwd} from '@shopify/cli-kit/node/path' import {canRunDoctorRelease} from '@shopify/cli-kit/node/context/local' +import {renderConfirmationPrompt, RenderConfirmationPromptOptions} from '@shopify/cli-kit/node/ui' export default class DoctorReleaseTheme extends Command { static description = 'Run all theme command doctor-release tests' @@ -39,7 +40,16 @@ export default class DoctorReleaseTheme extends Command { if (!canRunDoctorRelease()) { return } + const promptOptions: RenderConfirmationPromptOptions = { + message: `This will run automated theme commands against your shop. It will modify remote themes. Please confirm before running.`, + confirmationMessage: 'Yes I understand', + cancellationMessage: 'No, cancel the command', + } + const confirmed = await renderConfirmationPrompt(promptOptions) + if (!confirmed) { + return + } const {flags} = await this.parse(DoctorReleaseTheme) const results = await runThemeDoctor({