(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestCreateWebhook_EnforcesPerUserCap(t *testing.T) { |
| 171 | pool := testutil.TestDB(t) |
| 172 | store := identity.NewStore(pool) |
| 173 | ctx := context.Background() |
| 174 | userID := webhookTestUser(t, store, "wh-cap") |
| 175 | |
| 176 | // Lower the cap for this user so we don't have to create 50 rows. |
| 177 | // account_limits has several NOT NULL columns without defaults |
| 178 | // (max_agents, max_domains, max_messages_month, max_storage_bytes) |
| 179 | // — seed reasonable values so the row passes constraints. |
| 180 | _, err := pool.Exec(ctx, |
| 181 | `INSERT INTO account_limits (user_id, plan_code, max_agents, max_domains, max_messages_month, max_storage_bytes, max_webhooks) |
| 182 | VALUES ($1, 'test', 10, 10, 100000, 1073741824, 2) |
| 183 | ON CONFLICT (user_id) DO UPDATE SET max_webhooks = 2`, userID) |
| 184 | if err != nil { |
| 185 | t.Fatalf("seed account_limits: %v", err) |
| 186 | } |
| 187 | |
| 188 | if _, err := store.CreateWebhook(ctx, userID, "https://a.example.com", "", []string{"email.received"}, identity.WebhookFilters{}); err != nil { |
| 189 | t.Fatalf("create 1: %v", err) |
| 190 | } |
| 191 | if _, err := store.CreateWebhook(ctx, userID, "https://b.example.com", "", []string{"email.received"}, identity.WebhookFilters{}); err != nil { |
| 192 | t.Fatalf("create 2: %v", err) |
| 193 | } |
| 194 | _, err = store.CreateWebhook(ctx, userID, "https://c.example.com", "", []string{"email.received"}, identity.WebhookFilters{}) |
| 195 | if !errors.Is(err, identity.ErrWebhookCapReached) { |
| 196 | t.Errorf("create at cap+1 err = %v, want ErrWebhookCapReached", err) |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | func TestCreateWebhook_DefaultCapWhenNoAccountLimits(t *testing.T) { |
| 201 | // Users without an account_limits row should default to |
nothing calls this directly
no test coverage detected