import { test, expect } from '@playwright/test'; test.describe('Webhook Endpoints', () => { test.describe('Stripe Webhook', () => { test('POST /api/v1/webhooks/stripe returns 401 with no signature', async ({ request }) => { const response = await request.post('/api/v1/webhooks/stripe', { data: { id: 'evt_test', type: 'test', data: {} }, }); expect(response.status()).toBe(401); const body = await response.json(); expect(body.error).toBeTruthy(); }); test('POST /api/v1/webhooks/stripe returns 200 with valid signature', async ({ request }) => { // Stripe requires a valid signature; without it, returns 401. // This test confirms the endpoint is reachable and rejects unsigned payloads. const response = await request.post('/api/v1/webhooks/stripe', { headers: { 'stripe-signature': 't=1,v1=invalid' }, data: { id: 'evt_test', type: 'test', data: {} }, }); // Returns 401 since signature is invalid expect(response.status()).toBeGreaterThanOrEqual(400); }); }); test.describe('Gaiia Webhook', () => { test('POST /api/v1/webhooks/gaiia/:org_id returns 404 for unknown org', async ({ request }) => { const response = await request.post('/api/v1/webhooks/gaiia/00000000-0000-0000-0000-000000000000', { data: { event: 'test' }, }); // 401 (no signature) or 404 (no integration) — both are valid rejection paths expect(response.status()).toBeGreaterThanOrEqual(400); }); }); test.describe('PagerDuty Webhook', () => { test('POST /api/v1/webhooks/pagerduty/:org_id returns 401 with no signature', async ({ request }) => { const response = await request.post( '/api/v1/webhooks/pagerduty/00000000-0000-0000-0000-000000000000', { data: { event: { event_type: 'incident.resolved', data: {} } } } ); expect(response.status()).toBe(401); }); }); test.describe('Agent Release Webhook', () => { test('POST /api/v1/webhooks/agent-release returns 401 without auth', async ({ request }) => { const response = await request.post('/api/v1/webhooks/agent-release'); expect(response.status()).toBe(401); const body = await response.json(); expect(body.error).toContain('Authorization'); }); test('POST /api/v1/webhooks/agent-release returns 401 with wrong bearer token', async ({ request, }) => { const response = await request.post('/api/v1/webhooks/agent-release', { headers: { authorization: 'Bearer wrong-token' }, }); expect(response.status()).toBe(401); }); test('POST /api/v1/webhooks/agent-release returns 200 with valid bearer token', async ({ request, }) => { const response = await request.post('/api/v1/webhooks/agent-release', { headers: { authorization: 'Bearer dev-webhook-secret' }, }); expect(response.status()).toBe(200); const body = await response.json(); expect(body.status).toBe('ok'); }); }); });