Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/app/src/cli/commands/app/config/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function mockHealthyProject() {
}

describe('app config validate command', () => {
test('keeps --client-id mutually exclusive with --config', () => {
expect(Validate.flags['client-id']?.exclusive).toEqual(['config'])
})

test('calls validateApp with json: false by default', async () => {
const app = testAppLinked()
mockHealthyProject()
Expand Down Expand Up @@ -72,6 +76,39 @@ describe('app config validate command', () => {
await expectValidationMetadataCalls({cmd_app_validate_json: true})
})

test('skips active config prompts when --client-id is passed', async () => {
const app = testAppLinked()
mockHealthyProject()
vi.mocked(linkedAppContext).mockResolvedValue({app} as Awaited<ReturnType<typeof linkedAppContext>>)
vi.mocked(validateApp).mockResolvedValue()

await Validate.run(['--client-id', 'api-key'], import.meta.url)

expect(selectActiveConfig).toHaveBeenCalledWith(expect.anything(), undefined, {skipPrompts: true})
expect(linkedAppContext).toHaveBeenCalledWith({
directory: expect.any(String),
clientId: 'api-key',
forceRelink: false,
userProvidedConfigName: undefined,
unsafeTolerateErrors: true,
})
expect(validateApp).toHaveBeenCalledWith(app, {json: false})
await expectValidationMetadataCalls({cmd_app_validate_json: false})
})

test('keeps active config prompts enabled when --client-id is not passed', async () => {
const app = testAppLinked()
mockHealthyProject()
vi.mocked(linkedAppContext).mockResolvedValue({app} as Awaited<ReturnType<typeof linkedAppContext>>)
vi.mocked(validateApp).mockResolvedValue()

await Validate.run([], import.meta.url)

expect(selectActiveConfig).toHaveBeenCalledWith(expect.anything(), undefined, {skipPrompts: false})
expect(validateApp).toHaveBeenCalledWith(app, {json: false})
await expectValidationMetadataCalls({cmd_app_validate_json: false})
})

test('outputs JSON issues when active config has TOML parse errors', async () => {
vi.mocked(Project.load).mockResolvedValue({errors: []} as unknown as Project)
vi.mocked(selectActiveConfig).mockResolvedValue({file: new TomlFile('shopify.app.toml', {})} as any)
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/commands/app/config/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class Validate extends AppLinkedCommand {
// Stage 2: Select active config and check for TOML parse errors scoped to it
let activeConfig
try {
activeConfig = await selectActiveConfig(project, flags.config)
activeConfig = await selectActiveConfig(project, flags.config, {skipPrompts: Boolean(flags['client-id'])})
} catch (err) {
if (err instanceof AbortError && flags.json) {
await recordValidationFailure(1, 1)
Expand Down
Loading