diff --git a/pagerduty/webhook_subscription.go b/pagerduty/webhook_subscription.go index 64a140e..546d6a4 100644 --- a/pagerduty/webhook_subscription.go +++ b/pagerduty/webhook_subscription.go @@ -9,7 +9,7 @@ type WebhookSubscriptionService service type WebhookSubscription struct { ID string `json:"id,omitempty"` Type string `json:"type,omitempty"` - Active bool `json:"active,omitempty"` + Active bool `json:"active"` Description string `json:"description,omitempty"` DeliveryMethod DeliveryMethod `json:"delivery_method,omitempty"` Events []string `json:"events,omitempty"` diff --git a/pagerduty/webhook_subscription_test.go b/pagerduty/webhook_subscription_test.go index df1a457..59bfe20 100644 --- a/pagerduty/webhook_subscription_test.go +++ b/pagerduty/webhook_subscription_test.go @@ -68,6 +68,41 @@ func TestWebhookSubscriptionCreate(t *testing.T) { } } +func TestWebhookSubscriptionCreateNonActive(t *testing.T) { + setup() + defer teardown() + + input := &WebhookSubscription{Active: false} + + mux.HandleFunc("/webhook_subscriptions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + v := new(WebhookSubscriptionPayload) + json.NewDecoder(r.Body).Decode(v) + encoded, _ := json.Marshal(v) + expectedMarshalValue := `{"webhook_subscription":{"active":false,"delivery_method":{"custom_headers":null},"filter":{}}}` + if string(encoded) != expectedMarshalValue { + t.Errorf("Marshalled body = %s, want %s", string(encoded), expectedMarshalValue) + } + if !reflect.DeepEqual(v.WebhookSubscription, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + w.Write([]byte(`{"webhook_subscription":{"id": "1"}}`)) + }) + + resp, _, err := client.WebhookSubscriptions.Create(input) + if err != nil { + t.Fatal(err) + } + + want := &WebhookSubscription{ + ID: "1", + } + + if !reflect.DeepEqual(resp, want) { + t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) + } +} + func TestWebhookSubscriptionGet(t *testing.T) { setup() defer teardown()