mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Test deliveries in the webhook deliveries table look the same as real ones. Test events are sent with `is_test: true` in the event payload, but the UI doesn't surface it, so there's no way to tell them apart at a glance. Closes FE-4710. ## Solution - Added an `isTestDelivery` helper that checks `eventPayload.is_test === true`. It uses a strict comparison, so values like the string `"true"` don't count. - Show a green "Test" badge next to the event name in the deliveries table. - Show the same badge in the header of the delivery details sheet, next to the status badge. - Added unit tests for the helper and component tests for the table and the sheet, each covering a test delivery and a real one. ## Review instructions 1. Open a project's webhooks page and select an endpoint. 2. Click the button to send a test event and wait for its delivery to appear in the Deliveries table. 3. Check that the new row has a green "Test" badge next to its event name, and that existing rows without it have no badge. 4. Click the test row and check that the delivery details sheet shows the "Test" badge next to the status badge in the header. 5. Click a non-test row and check that its sheet has no "Test" badge.
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { WebhookEndpoint } from './PlatformWebhooks.types'
|
|
import {
|
|
filterWebhookEndpoints,
|
|
getWebhookEndpointDisplayName,
|
|
isTestDelivery,
|
|
} from './PlatformWebhooks.utils'
|
|
|
|
const createEndpoint = (overrides: Partial<WebhookEndpoint> = {}): WebhookEndpoint => ({
|
|
id: 'endpoint-1',
|
|
url: 'https://hooks.example.com/billing',
|
|
description: '',
|
|
enabled: true,
|
|
eventTypes: ['v1.project.updated'],
|
|
customHeaders: [],
|
|
createdBy: 'user@supabase.io',
|
|
createdAt: '2026-03-16T00:00:00.000Z',
|
|
...overrides,
|
|
})
|
|
|
|
describe('PlatformWebhooks.utils', () => {
|
|
it('combines the endpoint url and subscribed event types', () => {
|
|
expect(
|
|
getWebhookEndpointDisplayName({
|
|
url: 'https://hooks.example.com/billing',
|
|
eventTypes: ['v1.project.paused', 'v1.project.created'],
|
|
})
|
|
).toBe('https://hooks.example.com/billing (v1.project.paused, v1.project.created)')
|
|
})
|
|
|
|
it('shows "all events" when subscribed to every event type', () => {
|
|
expect(
|
|
getWebhookEndpointDisplayName({
|
|
url: 'https://hooks.example.com/billing',
|
|
eventTypes: ['*'],
|
|
})
|
|
).toBe('https://hooks.example.com/billing (all events)')
|
|
})
|
|
|
|
it('filters endpoints by url and description', () => {
|
|
const endpoints = [
|
|
createEndpoint({ id: '1', url: 'https://hooks.example.com/billing' }),
|
|
createEndpoint({
|
|
id: '2',
|
|
url: 'https://hooks.slack.com/x',
|
|
description: 'operational alerts',
|
|
}),
|
|
]
|
|
|
|
expect(filterWebhookEndpoints(endpoints, 'billing')).toEqual([endpoints[0]])
|
|
expect(filterWebhookEndpoints(endpoints, 'slack')).toEqual([endpoints[1]])
|
|
expect(filterWebhookEndpoints(endpoints, 'alerts')).toEqual([endpoints[1]])
|
|
})
|
|
|
|
it('treats a delivery as a test only when is_test is exactly true', () => {
|
|
expect(isTestDelivery({ eventPayload: { is_test: true } })).toBe(true)
|
|
expect(isTestDelivery({ eventPayload: { is_test: false } })).toBe(false)
|
|
expect(isTestDelivery({ eventPayload: { is_test: 'true' } })).toBe(false)
|
|
expect(isTestDelivery({ eventPayload: {} })).toBe(false)
|
|
})
|
|
})
|