@@ -204,33 +204,16 @@ func Test_Env_AddCommand(t *testing.T) {
204204 )
205205 },
206206 },
207- "add a numeric variable using prompts to the .env file" : {
208- CmdArgs : []string {},
207+ "add a numeric variable to the .env file for remote runtime " : {
208+ CmdArgs : []string {"PORT" , "3000" },
209209 Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
210210 setupEnvAddDotenvMocks (ctx , cm , cf )
211- cm .IO .On (
212- "InputPrompt" ,
213- mock .Anything ,
214- "Variable name" ,
215- mock .Anything ,
216- ).Return (
217- "PORT" ,
218- nil ,
219- )
220- cm .IO .On (
221- "PasswordPrompt" ,
222- mock .Anything ,
223- "Variable value" ,
224- iostreams .MatchPromptConfig (iostreams.PasswordPromptConfig {
225- Flag : cm .Config .Flags .Lookup ("value" ),
226- }),
227- ).Return (
228- iostreams.PasswordPromptResponse {
229- Prompt : true ,
230- Value : "3000" ,
231- },
211+ manifestMock := & app.ManifestMockObject {}
212+ manifestMock .On ("GetManifestLocal" , mock .Anything , mock .Anything , mock .Anything ).Return (
213+ types.SlackYaml {AppManifest : types.AppManifest {Settings : & types.AppSettings {FunctionRuntime : types .Remote }}},
232214 nil ,
233215 )
216+ cm .AppClient .Manifest = manifestMock
234217 },
235218 ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
236219 cm .API .AssertNotCalled (t , "AddVariable" )
@@ -239,18 +222,39 @@ func Test_Env_AddCommand(t *testing.T) {
239222 assert .Equal (t , "PORT=3000\n " , string (content ))
240223 },
241224 },
242- "add a variable to the .env file for non-hosted app " : {
225+ "add a variable to the .env file when no runtime is set " : {
243226 CmdArgs : []string {"NEW_VAR" , "new_value" },
244227 Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
245228 setupEnvAddDotenvMocks (ctx , cm , cf )
229+ manifestMock := & app.ManifestMockObject {}
230+ manifestMock .On ("GetManifestLocal" , mock .Anything , mock .Anything , mock .Anything ).Return (types.SlackYaml {}, nil )
231+ cm .AppClient .Manifest = manifestMock
246232 err := afero .WriteFile (cf .Fs , ".env" , []byte ("# Config\n EXISTING=value\n " ), 0600 )
247233 assert .NoError (t , err )
248234 },
249235 ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
250236 cm .API .AssertNotCalled (t , "AddVariable" )
251237 content , err := afero .ReadFile (cm .Fs , ".env" )
252238 assert .NoError (t , err )
253- assert .Equal (t , "# Config\n EXISTING=value\n NEW_VAR=\" new_value\" \n " , string (content ))
239+ assert .Equal (t , "# Config\n EXISTING=value\n " + `NEW_VAR="new_value"` + "\n " , string (content ))
240+ },
241+ },
242+ "add a variable to the .env file when manifest fetch errors" : {
243+ CmdArgs : []string {"API_KEY" , "sk-1234" },
244+ Setup : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
245+ setupEnvAddDotenvMocks (ctx , cm , cf )
246+ manifestMock := & app.ManifestMockObject {}
247+ manifestMock .On ("GetManifestLocal" , mock .Anything , mock .Anything , mock .Anything ).Return (
248+ types.SlackYaml {},
249+ slackerror .New (slackerror .ErrSDKHookNotFound ),
250+ )
251+ cm .AppClient .Manifest = manifestMock
252+ },
253+ ExpectedAsserts : func (t * testing.T , ctx context.Context , cm * shared.ClientsMock ) {
254+ cm .API .AssertNotCalled (t , "AddVariable" )
255+ content , err := afero .ReadFile (cm .Fs , ".env" )
256+ assert .NoError (t , err )
257+ assert .Equal (t , `API_KEY="sk-1234"` + "\n " , string (content ))
254258 },
255259 },
256260 }, func (cf * shared.ClientFactory ) * cobra.Command {
@@ -292,20 +296,11 @@ func setupEnvAddHostedMocks(ctx context.Context, cm *shared.ClientsMock, cf *sha
292296 cf .SDKConfig .WorkingDirectory = "/slack/path/to/project"
293297}
294298
295- // setupEnvAddDotenvMocks prepares common mocks for non-hosted (dotenv) app tests
299+ // setupEnvAddDotenvMocks prepares common mocks for non-hosted (dotenv) app tests.
300+ // Callers must set their own manifest mock on cm.AppClient.Manifest.
296301func setupEnvAddDotenvMocks (_ context.Context , cm * shared.ClientsMock , cf * shared.ClientFactory ) {
297302 cf .SDKConfig = hooks .NewSDKConfigMock ()
298303 cm .AddDefaultMocks ()
299304
300- mockDevApp := types.App {
301- TeamID : "T1" ,
302- TeamDomain : "team1" ,
303- AppID : "A0123456789" ,
304- IsDev : true ,
305- }
306- appSelectMock := prompts .NewAppSelectMock ()
307- appSelectPromptFunc = appSelectMock .AppSelectPrompt
308- appSelectMock .On ("AppSelectPrompt" , mock .Anything , mock .Anything , prompts .ShowAllEnvironments , prompts .ShowInstalledAppsOnly ).Return (prompts.SelectedApp {Auth : mockAuth , App : mockDevApp }, nil )
309-
310305 cm .Config .Flags .String ("value" , "" , "mock value flag" )
311306}
0 commit comments