@@ -162,6 +162,74 @@ func TestKeyBulkCreate(t *testing.T) {
162162 }
163163}
164164
165+ func TestKeyBulkUpdate_UseAutomationsFalse (t * testing.T ) {
166+ client , mux , _ , teardown := setup ()
167+ defer teardown ()
168+
169+ mux .HandleFunc (
170+ fmt .Sprintf ("/api2/projects/%s/keys" , testProjectID ),
171+ func (w http.ResponseWriter , r * http.Request ) {
172+ w .Header ().Set ("Content-Type" , "application/json" )
173+ testMethod (t , r , "PUT" )
174+ testHeader (t , r , "X-Api-Token" , testApiToken )
175+
176+ data := `{"keys":[{"key_id":123,"description":"Updated"}],"use_automations":false}`
177+ req := new (bytes.Buffer )
178+ _ = json .Compact (req , []byte (data ))
179+ testBody (t , r , req .String ())
180+
181+ _ , _ = fmt .Fprint (w , `{
182+ "project_id": "` + testProjectID + `",
183+ "keys": [{"key_id": 123}]
184+ }` )
185+ })
186+
187+ keysJSON := `[{"key_id":123,"description":"Updated"}]`
188+ args := []string {"key" , "bulk-update" , "--keys=" + keysJSON , "--project-id=" + testProjectID , "--use-automations=false" }
189+ rootCmd .SetArgs (args )
190+ keyBulkUpdateCmd .PreRun = func (cmd * cobra.Command , args []string ) {
191+ Api = client
192+ }
193+
194+ if err := rootCmd .Execute (); err != nil {
195+ t .Errorf ("Expected no error, got %v" , err )
196+ }
197+ }
198+
199+ func TestKeyBulkCreate_UseAutomationsFalse (t * testing.T ) {
200+ client , mux , _ , teardown := setup ()
201+ defer teardown ()
202+
203+ mux .HandleFunc (
204+ fmt .Sprintf ("/api2/projects/%s/keys" , testProjectID ),
205+ func (w http.ResponseWriter , r * http.Request ) {
206+ w .Header ().Set ("Content-Type" , "application/json" )
207+ testMethod (t , r , "POST" )
208+ testHeader (t , r , "X-Api-Token" , testApiToken )
209+
210+ data := `{"keys":[{"key_name":"welcome","platforms":["web"],"tags":[]}],"use_automations":false}`
211+ req := new (bytes.Buffer )
212+ _ = json .Compact (req , []byte (data ))
213+ testBody (t , r , req .String ())
214+
215+ _ , _ = fmt .Fprint (w , `{
216+ "project_id": "` + testProjectID + `",
217+ "keys": [{"key_id": 789}]
218+ }` )
219+ })
220+
221+ keysJSON := `[{"key_name":"welcome","platforms":["web"],"tags":[]}]`
222+ args := []string {"key" , "bulk-create" , "--keys=" + keysJSON , "--project-id=" + testProjectID , "--use-automations=false" }
223+ rootCmd .SetArgs (args )
224+ keyBulkCreateCmd .PreRun = func (cmd * cobra.Command , args []string ) {
225+ Api = client
226+ }
227+
228+ if err := rootCmd .Execute (); err != nil {
229+ t .Errorf ("Expected no error, got %v" , err )
230+ }
231+ }
232+
165233func TestKeyBulkUpdate_InvalidJSON (t * testing.T ) {
166234 client , _ , _ , teardown := setup ()
167235 defer teardown ()
@@ -193,3 +261,35 @@ func TestKeyBulkCreate_InvalidJSON(t *testing.T) {
193261 t .Error ("Expected error for invalid JSON, got nil" )
194262 }
195263}
264+
265+ func TestKeyBulkUpdate_EmptyKeys (t * testing.T ) {
266+ client , _ , _ , teardown := setup ()
267+ defer teardown ()
268+
269+ args := []string {"key" , "bulk-update" , "--keys=[]" , "--project-id=" + testProjectID }
270+ rootCmd .SetArgs (args )
271+ keyBulkUpdateCmd .PreRun = func (cmd * cobra.Command , args []string ) {
272+ Api = client
273+ }
274+
275+ err := rootCmd .Execute ()
276+ if err == nil {
277+ t .Error ("Expected error for empty keys, got nil" )
278+ }
279+ }
280+
281+ func TestKeyBulkCreate_EmptyKeys (t * testing.T ) {
282+ client , _ , _ , teardown := setup ()
283+ defer teardown ()
284+
285+ args := []string {"key" , "bulk-create" , "--keys=[]" , "--project-id=" + testProjectID }
286+ rootCmd .SetArgs (args )
287+ keyBulkCreateCmd .PreRun = func (cmd * cobra.Command , args []string ) {
288+ Api = client
289+ }
290+
291+ err := rootCmd .Execute ()
292+ if err == nil {
293+ t .Error ("Expected error for empty keys, got nil" )
294+ }
295+ }
0 commit comments