TestEventsDisabledReturns501 pins the gate: when the durable event log is off (EventsEnabled=false, i.e. WEBHOOKS_OUTBOX_ENABLED unset in prod), the list/get/redeliver endpoints must return 501 events_log_disabled rather than querying the empty webhook_events table and masquerading as "no events".
(t *testing.T)
| 127 | // list/get/redeliver endpoints must return 501 events_log_disabled rather than |
| 128 | // querying the empty webhook_events table and masquerading as "no events". |
| 129 | func TestEventsDisabledReturns501(t *testing.T) { |
| 130 | srv := httptest.NewServer(New(Deps{ |
| 131 | EventsEnabled: false, |
| 132 | Authenticator: func(r *http.Request) (*identity.User, error) { |
| 133 | if r.Header.Get("Authorization") == "Bearer good" { |
| 134 | return &identity.User{ID: "u_1", Email: "owner@acme.com"}, nil |
| 135 | } |
| 136 | return nil, errors.New("unauthorized") |
| 137 | }, |
| 138 | })) |
| 139 | defer srv.Close() |
| 140 | |
| 141 | for _, path := range []string{"/v1/events?limit=5", "/v1/events/evt_a"} { |
| 142 | code, body := getJSON(t, srv.URL+path, "good") |
| 143 | if code != 501 || errCode(body) != "events_log_disabled" { |
| 144 | t.Fatalf("GET %s: want 501 events_log_disabled, got %d %v", path, code, body) |
| 145 | } |
| 146 | } |
| 147 | code, body := postJSON(t, srv.URL+"/v1/events/evt_a/redeliver", "good", map[string]any{}) |
| 148 | if code != 501 || errCode(body) != "events_log_disabled" { |
| 149 | t.Fatalf("redeliver: want 501 events_log_disabled, got %d %v", code, body) |
| 150 | } |
| 151 | } |