@@ -8,6 +8,7 @@ import { SandboxSecretRemoveCommand } from './sandbox_secret_remove_command.js';
8
8
import { printer } from '@aws-amplify/cli-core' ;
9
9
10
10
const testSecretName = 'testSecretName' ;
11
+ const testSecretName2 = 'testSecretName2' ;
11
12
const testBackendId = 'testBackendId' ;
12
13
const testSandboxName = 'testSandboxName' ;
13
14
@@ -18,6 +19,14 @@ void describe('sandbox secret remove command', () => {
18
19
'removeSecret' ,
19
20
( ) : Promise < void > => Promise . resolve ( )
20
21
) ;
22
+ const secretsRemoveMock = mock . method (
23
+ secretClient ,
24
+ 'removeSecrets' ,
25
+ ( ) : Promise < void > => Promise . resolve ( )
26
+ ) ;
27
+ const listSecretsMock = mock . method ( secretClient , 'listSecrets' , ( ) =>
28
+ Promise . resolve ( [ { name : testSecretName } , { name : testSecretName2 } ] )
29
+ ) ;
21
30
const printMock = mock . method ( printer , 'print' ) ;
22
31
23
32
const sandboxIdResolver : SandboxBackendIdResolver = {
@@ -77,13 +86,49 @@ void describe('sandbox secret remove command', () => {
77
86
] ) ;
78
87
} ) ;
79
88
89
+ void it ( 'remove all secrets' , async ( ) => {
90
+ await commandRunner . runCommand ( 'remove --all' ) ;
91
+ assert . equal ( listSecretsMock . mock . callCount ( ) , 1 ) ;
92
+ assert . deepStrictEqual ( listSecretsMock . mock . calls [ 0 ] . arguments , [
93
+ {
94
+ type : 'sandbox' ,
95
+ namespace : testBackendId ,
96
+ name : testSandboxName ,
97
+ } ,
98
+ ] ) ;
99
+
100
+ assert . equal ( secretsRemoveMock . mock . callCount ( ) , 1 ) ;
101
+ assert . deepStrictEqual ( secretsRemoveMock . mock . calls [ 0 ] . arguments , [
102
+ {
103
+ type : 'sandbox' ,
104
+ namespace : testBackendId ,
105
+ name : testSandboxName ,
106
+ } ,
107
+ [ testSecretName , testSecretName2 ] ,
108
+ ] ) ;
109
+ assert . equal (
110
+ printMock . mock . calls [ 0 ] . arguments ,
111
+ 'Successfully removed all secrets'
112
+ ) ;
113
+ } ) ;
114
+
80
115
void it ( 'show --help' , async ( ) => {
81
116
const output = await commandRunner . runCommand ( 'remove --help' ) ;
82
117
assert . match ( output , / R e m o v e a s a n d b o x s e c r e t / ) ;
83
118
} ) ;
84
119
85
- void it ( 'throws error if no secret name argument' , async ( ) => {
86
- const output = await commandRunner . runCommand ( 'remove' ) ;
87
- assert . match ( output , / N o t e n o u g h n o n - o p t i o n a r g u m e n t s / ) ;
120
+ void it ( 'throws error if no secret name argument and all flag' , async ( ) => {
121
+ const output = await commandRunner . runCommand ( `remove` ) ;
122
+ [
123
+ / I n v a l i d C o m m a n d I n p u t E r r o r : E i t h e r s e c r e t - n a m e o r a l l f l a g m u s t b e p r o v i d e d / ,
124
+ / R e s o l u t i o n : P r o v i d e e i t h e r s e c r e t - n a m e o r a l l f l a g / ,
125
+ ] . forEach ( ( cmd ) => assert . match ( output , new RegExp ( cmd ) ) ) ;
126
+ } ) ;
127
+
128
+ void it ( 'throws error if both --all flag and secret-name argument' , async ( ) => {
129
+ assert . match (
130
+ await commandRunner . runCommand ( `remove ${ testSecretName } --all` ) ,
131
+ / A r g u m e n t s a l l a n d s e c r e t - n a m e a r e m u t u a l l y e x c l u s i v e /
132
+ ) ;
88
133
} ) ;
89
134
} ) ;
0 commit comments