Skip to content

Commit b0d1bdb

Browse files
committed
Add intent value test
1 parent 4c784be commit b0d1bdb

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,5 +2450,67 @@ Please check the configuration in ${uiExtension.configurationPath}`),
24502450
expect(helperType).not.toContain('CreateApplicationEmailIntentRequest')
24512451
})
24522452
})
2453+
2454+
test('generates intent types from an intent schema file that declares a value schema', async () => {
2455+
const typeDefinitionsByFile = new Map<string, Set<string>>()
2456+
2457+
await inTemporaryDirectory(async (tmpDir) => {
2458+
const {extension} = await setupUIExtensionWithNodeModules({
2459+
tmpDir,
2460+
fileContent: '// Extension code',
2461+
apiVersion: '2025-10',
2462+
target: 'admin.app.intent.render',
2463+
})
2464+
2465+
// Given an intent schema file that declares a root-level `value` schema
2466+
const intentSchemaContent = JSON.stringify({
2467+
value: {
2468+
type: 'object',
2469+
properties: {
2470+
productId: {type: 'string'},
2471+
},
2472+
required: ['productId'],
2473+
},
2474+
inputSchema: {
2475+
type: 'object',
2476+
properties: {
2477+
title: {type: 'string'},
2478+
},
2479+
},
2480+
outputSchema: {
2481+
type: 'object',
2482+
properties: {
2483+
id: {type: 'string'},
2484+
},
2485+
},
2486+
})
2487+
await writeFile(joinPath(tmpDir, 'intent-schema.json'), intentSchemaContent)
2488+
;(extension.configuration.extension_points[0] as any).intents = [
2489+
{
2490+
action: 'edit',
2491+
type: 'shopify/Product',
2492+
schema: './intent-schema.json',
2493+
},
2494+
]
2495+
2496+
await writeFile(joinPath(tmpDir, 'tsconfig.json'), '{}')
2497+
2498+
// When
2499+
await extension.contributeToSharedTypeFile?.(typeDefinitionsByFile)
2500+
2501+
const shopifyDtsPath = joinPath(tmpDir, 'shopify.d.ts')
2502+
const types = Array.from(typeDefinitionsByFile.get(shopifyDtsPath) ?? [])
2503+
2504+
// Then - the value schema is compiled into EditShopifyProductIntentValue
2505+
// and wired through the request type.
2506+
expect(types).toHaveLength(1)
2507+
const typeDefinition = types[0]!
2508+
expect(typeDefinition).toContain('interface EditShopifyProductIntentValue')
2509+
expect(typeDefinition).toContain('productId: string;')
2510+
expect(typeDefinition).toContain('value?: EditShopifyProductIntentValue;')
2511+
// Sanity: the value type is not the `unknown` fallback used when no schema is provided.
2512+
expect(typeDefinition).not.toContain('type EditShopifyProductIntentValue = unknown')
2513+
})
2514+
})
24532515
})
24542516
})

0 commit comments

Comments
 (0)