Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added end-to-end tests for connecting agents and managing OAuth clients
Damian Legawiec858d3cd3d5e8
diff --git a/packages/dashboard/e2e/oauth-clients.spec.ts b/packages/dashboard/e2e/oauth-clients.spec.tsnew file mode 100644index 0000000000..ebcd5f8f0a--- /dev/null+++ b/packages/dashboard/e2e/oauth-clients.spec.ts@@ -0,0 +1,98 @@+import { expect, type Page, test } from '@playwright/test'+import { gotoIndex, login } from './helpers'++const AGENTS_PATH = (storeId: string) => `/${storeId}/settings/connected-apps`+const CLIENTS_PATH = (storeId: string) => `/${storeId}/settings/oauth-clients`+const CONNECT_CTA = /connect an agent/i+const REGISTER_CTA = /register a client/i++/**+ * Registers a client through the connect sheet, the way a merchant does:+ * pick the assistant, continue, and the sheet hands back its address and id.+ */+async function connectKnownClient(page: Page) {+ await page.getByRole('button', { name: CONNECT_CTA }).click()+ const sheet = page.getByRole('dialog')+ await expect(sheet.getByText(/choose the assistant/i)).toBeVisible()++ // The callback is filled in for a client we know, so a merchant never sees+ // a URL field — picking a name is the whole choice.+ await expect(sheet.getByText(/callback url/i)).toHaveCount(0)++ await sheet.getByText(/claude\.ai, claude desktop/i).click()+ await sheet.getByRole('button', { name: /^continue$/i }).click()++ return sheet+}++test.describe('connecting an agent', () => {+ test('registers the client and shows what to paste into it', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, AGENTS_PATH(creds.store_id), CONNECT_CTA)++ const sheet = await connectKnownClient(page)++ await expect(sheet.getByText(/ready to connect/i)).toBeVisible({ timeout: 15_000 })+ await expect(sheet.getByText(/mcp address/i)).toBeVisible()+ await expect(sheet.getByText(/client id/i)).toBeVisible()++ // Claude Code connects by command rather than by pasting an address, so+ // the two surfaces are tabbed rather than listed together.+ await sheet.getByRole('tab', { name: /claude code/i }).click()+ await expect(sheet.getByText(/claude mcp add/i)).toBeVisible()++ await sheet.getByRole('button', { name: /^done$/i }).click()+ })++ // Revoking keeps the registration so the same client can be connected+ // again — which is exactly why the row has to say what changed.+ test('says whether a registration is connected', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, AGENTS_PATH(creds.store_id), CONNECT_CTA)++ const sheet = await connectKnownClient(page)+ await expect(sheet.getByText(/ready to connect/i)).toBeVisible({ timeout: 15_000 })+ await sheet.getByRole('button', { name: /^done$/i }).click()++ // Registered but nobody has signed in through it yet.+ await expect(page.getByText(/not connected/i).first()).toBeVisible({ timeout: 15_000 })+ })+})++test.describe('oauth clients', () => {+ test('registers a client from a name and a callback', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, CLIENTS_PATH(creds.store_id), REGISTER_CTA)++ const name = `CI client ${Date.now()}`+ await page.getByRole('button', { name: REGISTER_CTA }).click()++ const sheet = page.getByRole('dialog')+ await sheet.locator('#oauth-application-name').fill(name)+ await sheet.locator('#oauth-application-redirect-uri').fill('https://ci.example.com/callback')+ await sheet.getByRole('button', { name: /^save$/i }).click()++ await expect(page.getByRole('row', { name: new RegExp(name) })).toBeVisible({+ timeout: 15_000,+ })+ })++ // The one field a merchant must not get wrong: authorization codes are+ // delivered to it, so a plain-http host would hand them away.+ test('refuses a callback that is not https', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, CLIENTS_PATH(creds.store_id), REGISTER_CTA)++ await page.getByRole('button', { name: REGISTER_CTA }).click()+ const sheet = page.getByRole('dialog')+ await sheet.locator('#oauth-application-name').fill(`CI insecure ${Date.now()}`)+ await sheet.locator('#oauth-application-redirect-uri').fill('http://insecure.example.com/cb')+ await sheet.getByRole('button', { name: /^save$/i }).click()++ // Shown twice: once as a banner at the top of the form, once under the+ // field that caused it.+ await expect(+ sheet.getByRole('alert').filter({ hasText: /must start with https/i }),+ ).toBeVisible({ timeout: 15_000 })+ })+})diff --git a/packages/dashboard/src/components/spree/oauth-application-sheet.tsx b/packages/dashboard/src/components/spree/oauth-application-sheet.tsxindex 037d8bdb56..5b88e0e008 100644--- a/packages/dashboard/src/components/spree/oauth-application-sheet.tsx+++ b/packages/dashboard/src/components/spree/oauth-application-sheet.tsx@@ -129,7 +129,7 @@ export function OauthApplicationSheet({{t('admin.common.cancel')}</Button><Button type="submit" disabled={save.isPending}>- {t('admin.common.save')}+ {t('admin.actions.save')}</Button></SheetFooter></form>diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/oauth-clients.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/oauth-clients.tsxindex 22e7a5ac36..5201412684 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/oauth-clients.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/oauth-clients.tsx@@ -48,7 +48,7 @@ function OauthClientsSettingsPage() {name: client.name,}),variant: 'destructive',- confirmLabel: t('admin.common.delete'),+ confirmLabel: t('admin.actions.delete'),})if (!ok) return@@ -89,13 +89,13 @@ function OauthClientsSettingsPage() {actions={[{key: 'edit',- label: t('admin.common.edit'),+ label: t('admin.actions.edit'),visible: permissions.can('update', Subject.OauthApplication),onSelect: () => openForm(client),},{key: 'delete',- label: t('admin.common.delete'),+ label: t('admin.actions.delete'),destructive: true,visible: permissions.can('destroy', Subject.OauthApplication),disabled: remove.isPending,