Skip to content

Commit add987b

Browse files
committed
Address webhook review feedback
1 parent 52ac9f5 commit add987b

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

internal/commands/webhook.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ var webhookCreateCmd = &cobra.Command{
268268
SubscribedActions: webhookCreateActions,
269269
}
270270

271-
raw, _, err := ac.Webhooks().Create(cmd.Context(), boardID, req)
271+
raw, resp, err := ac.Webhooks().Create(cmd.Context(), boardID, req)
272272
if err != nil {
273273
return convertSDKError(err)
274274
}
@@ -287,7 +287,11 @@ var webhookCreateCmd = &cobra.Command{
287287
}
288288
}
289289

290-
printMutation(data, "", breadcrumbs)
290+
if location := resp.Headers.Get("Location"); location != "" {
291+
printMutationWithLocation(data, location, breadcrumbs)
292+
} else {
293+
printMutation(data, "", breadcrumbs)
294+
}
291295
return nil
292296
},
293297
}
@@ -394,16 +398,22 @@ var webhookReactivateCmd = &cobra.Command{
394398
webhookID := args[0]
395399

396400
ac := getSDK()
397-
if _, err := ac.Webhooks().Activate(cmd.Context(), boardID, webhookID); err != nil {
401+
resp, err := ac.Webhooks().Activate(cmd.Context(), boardID, webhookID)
402+
if err != nil {
398403
return convertSDKError(err)
399404
}
400405

406+
data := normalizeAny(resp.Data)
407+
if data == nil {
408+
data = map[string]any{"id": webhookID, "active": true}
409+
}
410+
401411
breadcrumbs := []Breadcrumb{
402412
breadcrumb("show", fmt.Sprintf("fizzy webhook show --board %s %s", boardID, webhookID), "View webhook"),
403413
breadcrumb("webhooks", fmt.Sprintf("fizzy webhook list --board %s", boardID), "List webhooks"),
404414
}
405415

406-
printMutation(map[string]any{}, "", breadcrumbs)
416+
printMutation(data, "", breadcrumbs)
407417
return nil
408418
},
409419
}

internal/commands/webhook_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ func TestWebhookShow(t *testing.T) {
215215
if !result.Response.OK {
216216
t.Error("expected success response")
217217
}
218-
if got := mock.GetWithPaginationCalls[0].Path; got != "/boards/board-1/webhooks/wh-1" {
218+
if len(mock.GetCalls) != 1 {
219+
t.Fatalf("expected 1 GET call, got %d", len(mock.GetCalls))
220+
}
221+
if got := mock.GetCalls[0].Path; got != "/boards/board-1/webhooks/wh-1" {
219222
t.Errorf("expected path '/boards/board-1/webhooks/wh-1', got '%s'", got)
220223
}
221224
})
@@ -241,6 +244,7 @@ func TestWebhookCreate(t *testing.T) {
241244
mock := NewMockClient()
242245
mock.PostResponse = &client.APIResponse{
243246
StatusCode: 201,
247+
Location: "/boards/board-1/webhooks/wh-new",
244248
Data: map[string]any{
245249
"id": "wh-new",
246250
"name": "My Hook",
@@ -276,6 +280,9 @@ func TestWebhookCreate(t *testing.T) {
276280
if body["url"] != "https://example.com/hook" {
277281
t.Errorf("expected url 'https://example.com/hook', got '%v'", body["url"])
278282
}
283+
if got := result.Response.Context["location"]; got != "/boards/board-1/webhooks/wh-new" {
284+
t.Errorf("expected location context, got %v", got)
285+
}
279286
})
280287

281288
t.Run("creates webhook with actions", func(t *testing.T) {
@@ -472,7 +479,7 @@ func TestWebhookReactivate(t *testing.T) {
472479
},
473480
}
474481

475-
SetTestModeWithSDK(mock)
482+
result := SetTestModeWithSDK(mock)
476483
SetTestConfig("token", "account", "https://api.example.com")
477484
defer resetTest()
478485

@@ -484,6 +491,13 @@ func TestWebhookReactivate(t *testing.T) {
484491
if mock.PostCalls[0].Path != "/boards/board-1/webhooks/wh-1/activation.json" {
485492
t.Errorf("expected path '/boards/board-1/webhooks/wh-1/activation.json', got '%s'", mock.PostCalls[0].Path)
486493
}
494+
data, ok := result.Response.Data.(map[string]any)
495+
if !ok {
496+
t.Fatalf("expected response data map, got %T", result.Response.Data)
497+
}
498+
if data["id"] != "wh-1" || data["active"] != true {
499+
t.Fatalf("expected activated webhook data, got %#v", data)
500+
}
487501
})
488502

489503
t.Run("requires board", func(t *testing.T) {

0 commit comments

Comments
 (0)