@@ -5,6 +5,7 @@ import type { Paths } from 'env-paths'
55import type log4js from 'log4js'
66
77import type { CLIConfig , loadConfig } from '../../../lib/cli-config.js'
8+ import type { yellow } from '../../../lib/colors.js'
89import type { ensureDir } from '../../../lib/file-util.js'
910import type { buildDefaultLog4jsConfig , loadLog4jsConfig } from '../../../lib/log-utils.js'
1011import type { SmartThingsCommandFlags } from '../../../lib/command/smartthings-command.js'
@@ -30,6 +31,11 @@ jest.unstable_mockModule('../../../lib/cli-config.js', () => ({
3031 loadConfig : loadConfigMock ,
3132} ) )
3233
34+ const yellowMock = jest . fn < typeof yellow > ( )
35+ jest . unstable_mockModule ( '../../../lib/colors.js' , ( ) => ( {
36+ yellow : yellowMock ,
37+ } ) )
38+
3339const ensureDirMock = jest . fn < typeof ensureDir > ( )
3440jest . unstable_mockModule ( '../../../lib/file-util.js' , ( ) => ( {
3541 ensureDir : ensureDirMock ,
@@ -58,6 +64,7 @@ jest.unstable_mockModule('../../../lib/yargs-transition-temp.js', () => ({
5864} ) )
5965
6066const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { /* do nothing */ } )
67+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { /* do nothing */ } )
6168
6269
6370const {
@@ -94,6 +101,7 @@ describe('smartThingsCommand', () => {
94101 . mockReturnValue ( true )
95102 const cliConfig = {
96103 profile : { } ,
104+ mergedProfiles : { } ,
97105 booleanConfigValue : booleanConfigValueMock ,
98106 } as unknown as CLIConfig
99107 loadConfigMock . mockResolvedValue ( cliConfig )
@@ -121,5 +129,31 @@ describe('smartThingsCommand', () => {
121129 } , loggerMock )
122130 expect ( defaultTableGeneratorMock ) . toHaveBeenCalledTimes ( 1 )
123131 expect ( defaultTableGeneratorMock ) . toHaveBeenCalledWith ( { groupRows : true } )
132+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( )
133+ } )
134+
135+ it ( 'warns when a non-default profile is missing' , async ( ) => {
136+ yellowMock . mockReturnValueOnce ( 'yellow warning' )
137+
138+ await smartThingsCommand ( { profile : 'other' } )
139+
140+ expect ( yellowMock ) . toHaveBeenCalledExactlyOnceWith (
141+ 'warning: profile other not found in configuration\n' +
142+ 'To use a profile with no configuration options, add "other: {}" to config.yaml.\n' +
143+ 'See https://github.com/SmartThingsCommunity/smartthings-cli/blob/main/doc/configuration.md#profiles' +
144+ ' for more information.' ,
145+ )
146+ expect ( consoleWarnSpy ) . toHaveBeenCalledExactlyOnceWith ( 'yellow warning' )
147+ } )
148+
149+ it ( 'does not warn when a non-default profile exists but is empty' , async ( ) => {
150+ loadConfigMock . mockResolvedValueOnce ( {
151+ ...cliConfig ,
152+ mergedProfiles : { other : { } } ,
153+ } as unknown as CLIConfig )
154+
155+ await smartThingsCommand ( { profile : 'other' } )
156+
157+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( )
124158 } )
125159} )
0 commit comments