@@ -63,7 +63,7 @@ describe('config env Command', () => {
6363 nock ( 'https://api.particle.io/v1' )
6464 . intercept ( '/env-vars' , 'GET' )
6565 . reply ( 200 , sandboxList ) ;
66- await envVarsCommands . list ( { } ) ;
66+ await envVarsCommands . list ( { sandbox : true } ) ;
6767 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Retrieving environment variables...' ) ;
6868 const writeCalls = envVarsCommands . ui . write . getCalls ( ) . map ( c => c . args [ 0 ] ) ;
6969 const blocks = parseBlocksFromCalls ( writeCalls ) ;
@@ -88,11 +88,11 @@ describe('config env Command', () => {
8888 ] ) ;
8989 } ) ;
9090
91- it ( 'list all env vars for a device that belongs to a product ' , async ( ) => {
91+ it ( 'list all env vars for a device' , async ( ) => {
9292 nock ( 'https://api.particle.io/v1' )
93- . intercept ( '/products/product-id-123/ env-vars/abc123' , 'GET' )
93+ . intercept ( '/env-vars/abc123' , 'GET' )
9494 . reply ( 200 , sandboxDeviceProductList ) ;
95- await envVarsCommands . list ( { product : 'product-id-123' , device : 'abc123' } ) ;
95+ await envVarsCommands . list ( { device : 'abc123' } ) ;
9696 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Retrieving environment variables...' ) ;
9797 const writeCalls = envVarsCommands . ui . write . getCalls ( ) . map ( c => c . args [ 0 ] ) ;
9898 const blocks = parseBlocksFromCalls ( writeCalls ) ;
@@ -108,7 +108,7 @@ describe('config env Command', () => {
108108 nock ( 'https://api.particle.io/v1' )
109109 . intercept ( '/env-vars' , 'GET' )
110110 . reply ( 200 , emptyList ) ;
111- await envVarsCommands . list ( { } ) ;
111+ await envVarsCommands . list ( { sandbox : true } ) ;
112112 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Retrieving environment variables...' ) ;
113113 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( 'No environment variables found.' ) ;
114114 } ) ;
@@ -117,7 +117,7 @@ describe('config env Command', () => {
117117 nock ( 'https://api.particle.io/v1' )
118118 . intercept ( '/env-vars' , 'GET' )
119119 . reply ( 200 , emptyListWithKeys ) ;
120- await envVarsCommands . list ( { } ) ;
120+ await envVarsCommands . list ( { sandbox : true } ) ;
121121 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Retrieving environment variables...' ) ;
122122 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( 'No environment variables found.' ) ;
123123 } ) ;
@@ -128,7 +128,7 @@ describe('config env Command', () => {
128128 nock ( 'https://api.particle.io/v1' )
129129 . intercept ( '/env-vars' , 'PATCH' )
130130 . reply ( 200 , sandboxList ) ;
131- await envVarsCommands . setEnvVars ( { params } ) ;
131+ await envVarsCommands . setEnvVars ( { params, sandbox : true } ) ;
132132 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Setting environment variable...' ) ;
133133 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( `Key ${ params . key } has been successfully set.` ) ;
134134 } ) ;
@@ -143,7 +143,7 @@ describe('config env Command', () => {
143143 . reply ( 400 , apiError ) ;
144144 let error ;
145145 try {
146- await envVarsCommands . setEnvVars ( { params : { } } ) ;
146+ await envVarsCommands . setEnvVars ( { params : { } , sandbox : true } ) ;
147147 } catch ( _error ) {
148148 error = _error ;
149149 }
@@ -190,7 +190,7 @@ describe('config env Command', () => {
190190 receivedBody = requestBody ;
191191 return [ 200 , { } ] ;
192192 } ) ;
193- await envVarsCommands . deleteEnv ( { params } ) ;
193+ await envVarsCommands . deleteEnv ( { params, sandbox : true } ) ;
194194 expect ( receivedBody ) . to . deep . equal ( { ops : [ { key : 'FOO' , op : 'Unset' } ] } ) ;
195195 expect ( envVarsCommands . ui . showBusySpinnerUntilResolved ) . calledWith ( 'Deleting environment variable...' ) ;
196196 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( `Key ${ params . key } has been successfully deleted.` ) ;
@@ -240,4 +240,42 @@ describe('config env Command', () => {
240240 expect ( envVarsCommands . ui . write ) . to . have . been . calledWith ( `Key ${ params . key } has been successfully deleted.` ) ;
241241 } ) ;
242242 } ) ;
243+
244+ describe ( 'scope validation' , ( ) => {
245+ it ( 'throws error when no scope is provided' , async ( ) => {
246+ let error ;
247+ try {
248+ await envVarsCommands . list ( { } ) ;
249+ } catch ( _error ) {
250+ error = _error ;
251+ }
252+ expect ( error . message ) . to . equal ( 'You must specify one of: --sandbox, --org, --product, or --device' ) ;
253+ } ) ;
254+
255+ it ( 'throws error when multiple scopes are provided' , async ( ) => {
256+ let error ;
257+ try {
258+ await envVarsCommands . list ( { sandbox : true , org : 'my-org' } ) ;
259+ } catch ( _error ) {
260+ error = _error ;
261+ }
262+ expect ( error . message ) . to . equal ( 'You can only specify one scope at a time. You provided: --sandbox, --org' ) ;
263+ } ) ;
264+
265+ it ( 'throws error when all scopes are provided' , async ( ) => {
266+ let error ;
267+ try {
268+ await envVarsCommands . setEnvVars ( {
269+ params : { key : 'FOO' , value : 'bar' } ,
270+ sandbox : true ,
271+ org : 'my-org' ,
272+ product : 'my-product' ,
273+ device : 'abc123'
274+ } ) ;
275+ } catch ( _error ) {
276+ error = _error ;
277+ }
278+ expect ( error . message ) . to . equal ( 'You can only specify one scope at a time. You provided: --sandbox, --org, --product, --device' ) ;
279+ } ) ;
280+ } ) ;
243281} ) ;
0 commit comments