@@ -138,12 +138,13 @@ describe('config env Command', () => {
138138 error_description : 'Validation error: : Must only contain uppercase letters, numbers, and underscores. Must not start with a number. at "ops[0].key"' ,
139139 error :'invalid_request'
140140 } ;
141+ const params = { key : 'invalid-key' , value : 'bar' } ; // Invalid key with dash
141142 nock ( 'https://api.particle.io/v1' )
142143 . intercept ( '/env' , 'PATCH' )
143144 . reply ( 400 , apiError ) ;
144145 let error ;
145146 try {
146- await envVarsCommands . setEnvVars ( { params : { } , sandbox : true } ) ;
147+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
147148 } catch ( _error ) {
148149 error = _error ;
149150 }
@@ -178,6 +179,58 @@ describe('config env Command', () => {
178179 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Setting environment variable...' ) ;
179180 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( `Key ${ params . key } has been successfully set.` ) ;
180181 } ) ;
182+
183+ it ( 'set env var using key=value format' , async ( ) => {
184+ let receivedBody ;
185+ const params = { key : 'FOO=bar' } ;
186+ nock ( 'https://api.particle.io/v1' )
187+ . intercept ( '/env' , 'PATCH' )
188+ . reply ( ( uri , requestBody ) => {
189+ receivedBody = requestBody ;
190+ return [ 200 , sandboxList ] ;
191+ } ) ;
192+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
193+ expect ( receivedBody ) . to . deep . equal ( { ops : [ { key : 'FOO' , value : 'bar' , op : 'Set' } ] } ) ;
194+ expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Setting environment variable...' ) ;
195+ expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( 'Key FOO has been successfully set.' ) ;
196+ } ) ;
197+
198+ it ( 'set env var using key=value format with value containing equals sign' , async ( ) => {
199+ let receivedBody ;
200+ const params = { key : 'FOO=bar=baz' } ;
201+ nock ( 'https://api.particle.io/v1' )
202+ . intercept ( '/env' , 'PATCH' )
203+ . reply ( ( uri , requestBody ) => {
204+ receivedBody = requestBody ;
205+ return [ 200 , sandboxList ] ;
206+ } ) ;
207+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
208+ expect ( receivedBody ) . to . deep . equal ( { ops : [ { key : 'FOO' , value : 'bar=baz' , op : 'Set' } ] } ) ;
209+ expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Setting environment variable...' ) ;
210+ expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( 'Key FOO has been successfully set.' ) ;
211+ } ) ;
212+
213+ it ( 'throws error when key=value format is invalid (empty key)' , async ( ) => {
214+ const params = { key : '=bar' } ;
215+ let error ;
216+ try {
217+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
218+ } catch ( _error ) {
219+ error = _error ;
220+ }
221+ expect ( error . message ) . to . equal ( 'Invalid format. Use either "key value" or "key=value"' ) ;
222+ } ) ;
223+
224+ it ( 'throws error when neither key/value nor key=value format is provided' , async ( ) => {
225+ const params = { key : 'FOO' } ; // Missing value
226+ let error ;
227+ try {
228+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
229+ } catch ( _error ) {
230+ error = _error ;
231+ }
232+ expect ( error . message ) . to . equal ( 'Invalid format. Use either "key value" or "key=value"' ) ;
233+ } ) ;
181234 } ) ;
182235
183236 describe ( 'delete env vars' , ( ) => {
0 commit comments