(t *testing.T)
| 237 | } |
| 238 | |
| 239 | func TestUpdateWebhook_ReEnableCooldown(t *testing.T) { |
| 240 | pool := testutil.TestDB(t) |
| 241 | store := identity.NewStore(pool) |
| 242 | ctx := context.Background() |
| 243 | userID := webhookTestUser(t, store, "wh-cooldown") |
| 244 | w, _ := store.CreateWebhook(ctx, userID, "https://a.example.com", "", []string{"email.received"}, identity.WebhookFilters{}) |
| 245 | |
| 246 | // Simulate auto-disable that just happened. |
| 247 | _, _ = pool.Exec(ctx, `UPDATE webhooks SET enabled = false, auto_disabled_at = now() WHERE id = $1`, w.ID) |
| 248 | |
| 249 | tval := true |
| 250 | _, err := store.UpdateWebhook(ctx, w.ID, userID, identity.WebhookUpdate{Enabled: &tval}) |
| 251 | if !errors.Is(err, identity.ErrWebhookCooldown) { |
| 252 | t.Errorf("expected ErrWebhookCooldown, got %v", err) |
| 253 | } |
| 254 | |
| 255 | // Simulate an auto_disabled_at older than 5 min — re-enable should succeed. |
| 256 | _, _ = pool.Exec(ctx, `UPDATE webhooks SET auto_disabled_at = now() - interval '10 minutes' WHERE id = $1`, w.ID) |
| 257 | got, err := store.UpdateWebhook(ctx, w.ID, userID, identity.WebhookUpdate{Enabled: &tval}) |
| 258 | if err != nil { |
| 259 | t.Fatalf("re-enable after cooldown: %v", err) |
| 260 | } |
| 261 | if !got.Enabled { |
| 262 | t.Error("Enabled = false after successful re-enable") |
| 263 | } |
| 264 | if got.AutoDisabledAt != nil { |
| 265 | t.Error("auto_disabled_at not cleared after re-enable") |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | func TestRotateSecret_ReturnsNewPlaintext(t *testing.T) { |
| 270 | pool := testutil.TestDB(t) |
nothing calls this directly
no test coverage detected