Files
supabase/e2e/studio/features/database-webhooks.spec.ts
Joshen Limandcoderabbitai[bot] 2400e9537a Joshenlim/fe 4679 inconsistency with integrations that arent installed create (#52141)
## Context

Addresses some issues with the "One click integration" feature preview
for the following 3 integrations

### Database Webhooks
- The "Create a new hook" CTA can be clicked despite the integration not
being installed yet
- As such if you were to create a new webhook, you'll run into errors
- Am opting to follow the UX in wrappers where the dashboard will
install the integration for you if you're trying to create a new webhook
while the integration isn't installed yet
- So this allows users to go straight to creating webhooks without the
additional step of clicking "Install integration"
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/7fb70937-94c2-4095-9eef-4fb71347d132"
/>
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/7efcee65-34c0-438f-8fb5-3f0d855a0f34"
/>

### Cron and Queues
- The "Jobs" / "Queues" tab can be opened despite the integration not
being installed yet
- This results in a number of unnecessary API requests to fetch the data
for the corresponding grids, but they'd all error out since the database
extension isn't installed
- Opting to gate all the network calls via `enabled` if the integration
is not installed yet, and also render an empty state instead as such
(This aligns with the Stripe Sync Engine)
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/e8203162-a249-4da0-9ef9-f47df194b20f"
/>

## To test
- [ ] For database webhooks, verify that you can create a webhook
without having to click "Install integration" prior
- [ ] For cron and queues, verify that there's no network requests to
fetch their data if the integration is not installed yet while you're on
the jobs / queues pages

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-10-23 16:16:33 +08:00

226 lines
8.8 KiB
TypeScript

import { expect, Page } from '@playwright/test'
import { createTable, dropTable } from '../utils/db/index.js'
import { test } from '../utils/test.js'
import { toUrl } from '../utils/to-url.js'
const ensureWebhooksEnabled = async (page: Page, ref: string) => {
await page.goto(toUrl(`/project/${ref}/integrations/webhooks/overview`))
// The original "allow you to send real-time data" copy was removed when the
// webhooks page was migrated to the new integrations UI (PR #44277). Wait
// on the page-header heading instead — it's rendered whether or not the
// supabase_functions extension is enabled.
await expect(page.getByRole('heading', { name: 'Database Webhooks' })).toBeVisible({
timeout: 30000,
})
const enableButton = page.getByRole('button', { name: 'Enable webhooks' })
if ((await enableButton.count()) > 0) {
await enableButton.click()
await expect(page.getByText('Successfully enabled webhooks')).toBeVisible({ timeout: 15000 })
}
}
const navigateToWebhooksList = async (page: Page, ref: string) => {
await page.goto(toUrl(`/project/${ref}/integrations/webhooks/webhooks`))
await expect(page.getByPlaceholder('Search for a webhook')).toBeVisible({ timeout: 30000 })
}
const createWebhookViaUI = async (page: Page, hookName: string, tableName: string) => {
await page.getByRole('button', { name: 'Create webhook', exact: true }).click()
await expect(page.getByText('Create a new database webhook')).toBeVisible({ timeout: 10000 })
await page.locator('input[name="name"]').fill(hookName)
await page.getByRole('combobox').filter({ hasText: 'Select a table' }).click()
await page.getByRole('option', { name: new RegExp(tableName) }).click()
await page.locator('#event-INSERT').click()
await page
.getByPlaceholder('http://api.com/path/resource')
.fill('http://localhost:3000/test-webhook')
await page.locator('button[form="edit-hook-panel-form"]').click()
await expect(page.getByText(`Successfully created new webhook "${hookName}"`)).toBeVisible({
timeout: 10000,
})
}
const openWebhookEditor = async (page: Page, hookName: string) => {
const webhookText = page.getByText(hookName, { exact: true })
const webhookRow = page.locator('tr').filter({ has: webhookText })
await webhookRow.getByRole('button').click()
await page.getByRole('menuitem', { name: 'Edit hook' }).click()
await expect(page.getByText(`Update webhook ${hookName}`)).toBeVisible({ timeout: 10000 })
}
const addCustomHeader = async (page: Page, name: string, value: string) => {
await page.getByRole('button', { name: 'Add header' }).click()
await page.getByPlaceholder('Header name').last().fill(name)
await page.getByPlaceholder('Header value').last().fill(value)
}
const deleteWebhookViaUI = async (page: Page, name: string) => {
const webhookText = page.getByText(name, { exact: true })
const webhookRow = page.locator('tr').filter({ has: webhookText })
await webhookRow.getByRole('button').click()
await page.getByRole('menuitem', { name: 'Delete hook' }).click()
await expect(page.getByRole('heading', { name: 'Delete database webhook' })).toBeVisible()
await page.getByPlaceholder('Type in name of webhook').fill(name)
await page.getByRole('button', { name: `Delete ${name}` }).click()
await expect(page.getByText(`Successfully deleted ${name}`)).toBeVisible({ timeout: 10000 })
await expect(webhookRow).not.toBeVisible({ timeout: 10000 })
}
const setupTable = async (tableName: string) => {
await dropTable(tableName)
await createTable(tableName, 'data')
}
const uniqueNames = (prefix: string) => {
const i = test.info().parallelIndex
return { table: `pw_wh_${prefix}_tbl_${i}`, hook: `pw_wh_${prefix}_${i}` }
}
test.describe('Database Webhooks', () => {
test('can view webhooks list page', async ({ page, ref }) => {
await ensureWebhooksEnabled(page, ref)
await navigateToWebhooksList(page, ref)
await expect(page.getByPlaceholder('Search for a webhook')).toBeVisible()
await expect(page.getByRole('button', { name: 'Create webhook', exact: true })).toBeVisible()
})
test('can create a new webhook with correct toast message', async ({ page, ref }) => {
const { table, hook } = uniqueNames('create')
await setupTable(table)
try {
await ensureWebhooksEnabled(page, ref)
await navigateToWebhooksList(page, ref)
await page.getByRole('button', { name: 'Create webhook', exact: true }).click()
await expect(page.getByText('Create a new database webhook')).toBeVisible({ timeout: 10000 })
await page.locator('input[name="name"]').fill(hook)
await page.getByRole('combobox').filter({ hasText: 'Select a table' }).click()
await page.getByRole('option', { name: new RegExp(table) }).click()
await page.locator('#event-INSERT').click()
await page
.getByPlaceholder('http://api.com/path/resource')
.fill('http://localhost:3000/test-webhook')
await page.locator('button[form="edit-hook-panel-form"]').click()
await expect(page.getByText(`Successfully created new webhook "${hook}"`)).toBeVisible({
timeout: 10000,
})
await expect(page.getByText(hook, { exact: true })).toBeVisible({ timeout: 10000 })
} finally {
await dropTable(table)
}
})
test('can edit a webhook with correct toast message', async ({ page, ref }) => {
const { table, hook } = uniqueNames('edit')
await setupTable(table)
try {
await ensureWebhooksEnabled(page, ref)
await navigateToWebhooksList(page, ref)
await createWebhookViaUI(page, hook, table)
const webhookText = page.getByText(hook, { exact: true })
const webhookRow = page.locator('tr').filter({ has: webhookText })
await webhookRow.getByRole('button').click()
await page.getByRole('menuitem', { name: 'Edit hook' }).click()
await expect(page.getByText(`Update webhook ${hook}`)).toBeVisible({ timeout: 10000 })
const urlInput = page.getByPlaceholder('http://api.com/path/resource')
await urlInput.clear()
await urlInput.fill('http://localhost:3000/test-webhook-updated')
await page.getByRole('button', { name: 'Update webhook' }).click()
await expect(page.getByText(`Successfully updated webhook "${hook}"`)).toBeVisible({
timeout: 10000,
})
await expect(page.getByText('Webhook not found')).not.toBeVisible()
} finally {
await dropTable(table)
}
})
test('preserves webhook URL path and custom headers after editing', async ({ page, ref }) => {
const { table, hook } = uniqueNames('edit_persist')
const originalUrl = 'http://localhost:3000/test-webhook'
const updatedUrl = 'http://localhost:3000/test-webhook-updated/path'
const headerName = 'X-API-Key'
const headerValue = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12'
await setupTable(table)
try {
await ensureWebhooksEnabled(page, ref)
await navigateToWebhooksList(page, ref)
await createWebhookViaUI(page, hook, table)
await openWebhookEditor(page, hook)
await addCustomHeader(page, headerName, headerValue)
await page.getByRole('button', { name: 'Update webhook' }).click()
await expect(page.getByText(`Successfully updated webhook "${hook}"`)).toBeVisible({
timeout: 10000,
})
await openWebhookEditor(page, hook)
await expect(page.getByPlaceholder('http://api.com/path/resource')).toHaveValue(originalUrl)
await expect(page.getByPlaceholder('Header name').last()).toHaveValue(headerName)
await expect(page.getByPlaceholder('Header value').last()).toHaveValue(headerValue)
const urlInput = page.getByPlaceholder('http://api.com/path/resource')
await urlInput.clear()
await urlInput.fill(updatedUrl)
await page.getByRole('button', { name: 'Update webhook' }).click()
await expect(page.getByText(`Successfully updated webhook "${hook}"`)).toBeVisible({
timeout: 10000,
})
await openWebhookEditor(page, hook)
await expect(page.getByPlaceholder('http://api.com/path/resource')).toHaveValue(updatedUrl)
await expect(page.getByPlaceholder('Header name').last()).toHaveValue(headerName)
await expect(page.getByPlaceholder('Header value').last()).toHaveValue(headerValue)
} finally {
await dropTable(table)
}
})
test('can delete a webhook with correct toast message', async ({ page, ref }) => {
const { table, hook } = uniqueNames('delete')
await setupTable(table)
try {
await ensureWebhooksEnabled(page, ref)
await navigateToWebhooksList(page, ref)
await createWebhookViaUI(page, hook, table)
await deleteWebhookViaUI(page, hook)
await expect(page.getByText(`Successfully deleted ${hook}`)).toBeVisible({ timeout: 10000 })
await expect(page.getByText(hook, { exact: true })).not.toBeVisible()
} finally {
await dropTable(table)
}
})
})