1- import use , { UseOptions } from './use.js'
1+ import use , { UseOptions , useAppConfiguration } from './use.js'
22import { testApp , testAppWithConfig , testDeveloperPlatformClient } from '../../../models/app/app.test-data.js'
33import { getAppConfigurationFileName , getAppConfigurationContext } from '../../../models/app/loader.js'
4- import { clearCurrentConfigFile , setCachedAppInfo } from '../../local-storage.js'
4+ import { clearCurrentConfigFile , getCachedAppInfo , setCachedAppInfo } from '../../local-storage.js'
55import { selectConfigFile } from '../../../prompts/config.js'
66import { describe , expect , test , vi } from 'vitest'
77import { inTemporaryDirectory , writeFileSync } from '@shopify/cli-kit/node/fs'
88import { joinPath } from '@shopify/cli-kit/node/path'
99import { renderSuccess , renderWarning } from '@shopify/cli-kit/node/ui'
1010import { err , ok } from '@shopify/cli-kit/node/result'
11+ // Match the platform-native public artifact path.
12+ // eslint-disable-next-line no-restricted-imports
13+ import { resolve } from 'node:path'
1114
1215vi . mock ( '../../../prompts/config.js' )
1316vi . mock ( '../../local-storage.js' )
@@ -23,7 +26,7 @@ function mockContext(directory: string, configuration: Record<string, unknown>)
2326 project : { } as any ,
2427 activeConfig : {
2528 file : {
26- path : joinPath ( directory , 'shopify.app.toml' ) ,
29+ path : resolve ( directory , 'shopify.app.toml' ) ,
2730 content : configuration ,
2831 } ,
2932 source : 'flag' ,
@@ -297,3 +300,61 @@ function createConfigFile(tmp: string, fileName: string) {
297300 const filePath = joinPath ( tmp , fileName )
298301 writeFileSync ( filePath , '' )
299302}
303+
304+ test ( 'returns selected configuration facts without presentation' , async ( ) => {
305+ await inTemporaryDirectory ( async ( directory ) => {
306+ createConfigFile ( directory , 'shopify.app.toml' )
307+ vi . mocked ( getAppConfigurationFileName ) . mockReturnValue ( 'shopify.app.toml' )
308+ mockContext ( directory , { client_id : 'key' } )
309+ await expect ( useAppConfiguration ( { directory, configName : 'shopify.app.toml' } ) ) . resolves . toEqual ( {
310+ status : 'success' ,
311+ changed : true ,
312+ path : resolve ( directory , 'shopify.app.toml' ) ,
313+ clientId : 'key' ,
314+ } )
315+ expect ( renderSuccess ) . not . toHaveBeenCalled ( )
316+ expect ( setCachedAppInfo ) . toHaveBeenCalledWith ( { directory, configFile : 'shopify.app.toml' } )
317+ } )
318+ } )
319+
320+ test ( 'returns explicit nulls after resetting the preference without presentation' , async ( ) => {
321+ await inTemporaryDirectory ( async ( directory ) => {
322+ await expect ( useAppConfiguration ( { directory, reset : true } ) ) . resolves . toEqual ( {
323+ status : 'success' ,
324+ changed : false ,
325+ path : null ,
326+ clientId : null ,
327+ } )
328+ expect ( clearCurrentConfigFile ) . toHaveBeenCalledWith ( directory )
329+ expect ( renderSuccess ) . not . toHaveBeenCalled ( )
330+ } )
331+ } )
332+
333+ test . each ( [
334+ { previous : undefined , changed : true } ,
335+ { previous : 'shopify.app.toml' , changed : false } ,
336+ { previous : 'shopify.app.staging.toml' , changed : true } ,
337+ ] ) ( 'reports whether selection changes the preferred configuration: %j' , async ( { previous, changed} ) => {
338+ await inTemporaryDirectory ( async ( directory ) => {
339+ createConfigFile ( directory , 'shopify.app.toml' )
340+ vi . mocked ( getAppConfigurationFileName ) . mockReturnValue ( 'shopify.app.toml' )
341+ vi . mocked ( getCachedAppInfo ) . mockReturnValue ( { directory, configFile : previous } )
342+ mockContext ( directory , { client_id : 'key' } )
343+ await expect ( useAppConfiguration ( { directory, configName : 'shopify.app.toml' } ) ) . resolves . toMatchObject ( {
344+ status : 'success' ,
345+ changed,
346+ } )
347+ } )
348+ } )
349+
350+ test ( 'reports a change when resetting an existing preferred configuration' , async ( ) => {
351+ await inTemporaryDirectory ( async ( directory ) => {
352+ vi . mocked ( getCachedAppInfo ) . mockReturnValue ( { directory, configFile : 'shopify.app.toml' } )
353+ await expect ( useAppConfiguration ( { directory, reset : true } ) ) . resolves . toEqual ( {
354+ status : 'success' ,
355+ changed : true ,
356+ path : null ,
357+ clientId : null ,
358+ } )
359+ } )
360+ } )
0 commit comments