Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): report a rejected per-session plugin override
Yudhi Armyndharis0eb07a28f195
diff --git a/dashboard/src/pages/Plugins.test.ts b/dashboard/src/pages/Plugins.test.tsnew file mode 100644index 000000000..a16f38b61--- /dev/null+++ b/dashboard/src/pages/Plugins.test.ts@@ -0,0 +1,101 @@+// Render test for the per-session plugin config override under the bare `node --test` runner, on the+// ApiKeys.test.ts harness. PUT /plugins/:id/config/:sessionId reports a rejected save as 200 ++// {success:false}; the override form must show that failure, not "Saved".+import '../test-helpers/register-hooks.ts';+import { test, before, afterEach } from 'node:test';+import assert from 'node:assert/strict';+import { createElement } from 'react';+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';++function jsonResponse(data: unknown, status = 200): Response {+ return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });+}++const PLUGIN = {+ id: 'greeter',+ name: 'Greeter',+ version: '1.0.0',+ type: 'extension',+ status: 'enabled',+ config: { greeting: 'hello' },+ builtIn: false,+ provides: [],+ ingressCapable: false,+ configSchema: { type: 'object', properties: { greeting: { type: 'string', title: 'Greeting' } } },+ sessionScoped: true,+ activeSessions: ['*'],+ sessionConfig: {},+};++const SESSION = { id: 'sess-1', name: 'Main', status: 'ready', createdAt: '2026-01-01T00:00:00.000Z' };++const REJECTION = 'Cannot tell which entry was removed; reload and try again';++function installFetchStub(): void {+ globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {+ const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;+ const path = url.replace(/^https?:\/\/[^/]+/, '');+ const method = init?.method ?? 'GET';+ if (method === 'GET' && path === '/api/plugins') return Promise.resolve(jsonResponse([PLUGIN]));+ if (method === 'GET' && path === '/api/sessions') return Promise.resolve(jsonResponse([SESSION]));+ if (method === 'PUT' && path === `/api/plugins/${PLUGIN.id}/config/${SESSION.id}`) {+ return Promise.resolve(jsonResponse({ success: false, message: REJECTION }));+ }+ return Promise.resolve(jsonResponse([]));+ }) as typeof fetch;+}++let rtl: typeof import('@testing-library/react');+let Plugins: (typeof import('./Plugins.tsx'))['default'];+let ToastProvider: (typeof import('../components/Toast.tsx'))['ToastProvider'];+let queryClient: QueryClient | undefined;++before(async () => {+ const { installJsdomGlobals } = await import('../test-helpers/jsdom.ts');+ await installJsdomGlobals();+ // useTheme reads the colour-scheme media query; jsdom has no matchMedia.+ window.matchMedia ??= ((query: string) => ({+ matches: false,+ media: query,+ onchange: null,+ addListener() {},+ removeListener() {},+ addEventListener() {},+ removeEventListener() {},+ dispatchEvent: () => false,+ })) as typeof window.matchMedia;+ installFetchStub();+ const { i18nReady } = await import('../i18n/index.ts');+ await i18nReady;+ rtl = await import('@testing-library/react');+ ({ ToastProvider } = await import('../components/Toast.tsx'));+ ({ default: Plugins } = await import('./Plugins.tsx'));+});++afterEach(() => {+ rtl.cleanup();+ queryClient?.clear();+ queryClient = undefined;+});++test('a per-session override the server rejects reports the failure, not "Saved"', async () => {+ const { screen, fireEvent, findByText } = rtl;+ queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });+ rtl.render(+ createElement(+ QueryClientProvider,+ { client: queryClient },+ createElement(ToastProvider, null, createElement(Plugins)),+ ),+ );++ fireEvent.click(await screen.findByTitle('Configure'));+ fireEvent.click(await screen.findByRole('button', { name: 'Sessions' }));+ const select = await screen.findByRole('combobox', { name: 'Select a session…' });+ await findByText(select, 'Main');+ fireEvent.change(select, { target: { value: SESSION.id } });+ fireEvent.click(await screen.findByRole('button', { name: 'Save override' }));++ await screen.findByText(REJECTION);+ assert.equal(screen.queryByText('Configuration Saved'), null);+});diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsxindex f9be2a6a2..8f123d641 100644--- a/dashboard/src/pages/Plugins.tsx+++ b/dashboard/src/pages/Plugins.tsx@@ -435,7 +435,13 @@ function SessionsTab({ plugin }: { plugin: Plugin }) {if (overrideFormRef.current && !overrideFormRef.current.reportValidity()) return;setSavingOverride(true);try {- await pluginsApi.updateSessionConfig(plugin.id, selSession, sparseSessionOverride(overrideCfg, plugin));+ // A rejected save answers 200 + {success:false}; the absence of a throw is not success.+ const res = await pluginsApi.updateSessionConfig(+ plugin.id,+ selSession,+ sparseSessionOverride(overrideCfg, plugin),+ );+ if (!res.success) throw new Error(res.message);void queryClient.invalidateQueries({ queryKey: queryKeys.plugins });toast.success(t('plugins.toasts.savedTitle'), t('plugins.toasts.savedDesc'));} catch (err) {@@ -449,7 +455,8 @@ function SessionsTab({ plugin }: { plugin: Plugin }) {if (!selSession) return;setSavingOverride(true);try {- await pluginsApi.updateSessionConfig(plugin.id, selSession, {});+ const res = await pluginsApi.updateSessionConfig(plugin.id, selSession, {});+ if (!res.success) throw new Error(res.message);void queryClient.invalidateQueries({ queryKey: queryKeys.plugins });toast.success(t('plugins.toasts.savedTitle'), t('plugins.toasts.savedDesc'));} catch (err) {