Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): track each in-flight webhook test on its own
Yudhi Armyndharis689ab8e83fa9
diff --git a/dashboard/src/pages/Webhooks.test.ts b/dashboard/src/pages/Webhooks.test.tsindex c5861db44..5900805d9 100644--- a/dashboard/src/pages/Webhooks.test.ts+++ b/dashboard/src/pages/Webhooks.test.ts@@ -14,6 +14,13 @@ let createCalls = 0;let updateCalls = 0;let createBody: Record<string, unknown> | undefined;let updateBody: Record<string, unknown> | undefined;+// Test deliveries, recorded by path; each answers only once `releaseRequests` runs.+let testCalls: string[] = [];+let heldRequests: Promise<void> = Promise.resolve();+let releaseRequests: () => void = () => {};+function holdRequests(): void {+ heldRequests = new Promise<void>(resolve => (releaseRequests = resolve));+}function jsonResponse(data: unknown, status = 200): Response {return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });@@ -35,6 +42,10 @@ function installFetchStub(): void {updateBody = JSON.parse(String(init.body));return new Promise<Response>(() => {});}+ if (init?.method === 'POST' && /^\/api\/sessions\/sess-1\/webhooks\/[^/]+\/test$/.test(path)) {+ testCalls.push(path);+ return heldRequests.then(() => jsonResponse({ success: true, statusCode: 200 }));+ }if (path === '/api/webhooks') {if (webhooksStatus === 403) {return Promise.resolve(jsonResponse({ message: 'Insufficient permissions. Required: operator' }, 403));@@ -75,6 +86,9 @@ afterEach(() => {updateCalls = 0;createBody = undefined;updateBody = undefined;+ testCalls = [];+ releaseRequests();+ heldRequests = Promise.resolve();window.sessionStorage.setItem('openwa_user_role', 'viewer');});@@ -456,3 +470,32 @@ test('more than 20 filter conditions keep Save disabled', async () => {assert.equal(save.disabled, true);screen.getByText('Give every filter condition a value, and use at most 20 conditions.');});++test('a test in flight on one webhook is not ended by a test on another', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ webhooksStatus = 200;+ webhookList = ['w1', 'w2'].map(id => ({+ id,+ sessionId: 'sess-1',+ url: `https://example.test/${id}`,+ events: ['message.received'],+ active: true,+ }));+ holdRequests();+ renderWebhooks();+ await screen.findByText('https://example.test/w2');+ const [first, second] = screen.getAllByTitle<HTMLButtonElement>('Test');++ fireEvent.click(first);+ fireEvent.click(second);+ await waitFor(() => assert.equal(testCalls.length, 2));+ assert.equal(first.disabled, true, 'the first test is still in flight');+ assert.equal(second.disabled, true);++ fireEvent.click(first);+ await new Promise(resolve => setTimeout(resolve, 50));+ assert.equal(testCalls.length, 2);+ releaseRequests();+ await waitFor(() => assert.equal(first.disabled, false));+ assert.equal(second.disabled, false);+});diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsxindex f4bbdb9eb..953aebca0 100644--- a/dashboard/src/pages/Webhooks.tsx+++ b/dashboard/src/pages/Webhooks.tsx@@ -220,7 +220,9 @@ export function Webhooks() {}>({ url: '', events: ['message.received'], sessionId: '', filters: null });const [newAuth, setNewAuth] = useState(emptyNewAuth);const [editAuth, setEditAuth] = useState(emptyEditAuth);- const [testingId, setTestingId] = useState<string | null>(null);+ // Webhooks whose test delivery is in flight. One id per webhook, so testing another neither ends this+ // one's spinner nor lets a second click send a duplicate delivery.+ const [testingIds, setTestingIds] = useState<ReadonlySet<string>>(new Set());const toast = useToast();// Single source for the contact/group autocomplete in whichever modal is open.@@ -304,7 +306,7 @@ export function Webhooks() {};const handleTest = async (sessionId: string, id: string) => {- setTestingId(id);+ setTestingIds(current => new Set(current).add(id));try {const result = await webhookApi.test(sessionId, id);if (result.success) {@@ -319,7 +321,11 @@ export function Webhooks() {}),);} finally {- setTestingId(null);+ setTestingIds(current => {+ const next = new Set(current);+ next.delete(id);+ return next;+ });}};@@ -706,9 +712,9 @@ export function Webhooks() {className="icon-btn"title={t('webhooks.actions.test')}onClick={() => handleTest(webhook.sessionId, webhook.id)}- disabled={testingId === webhook.id}+ disabled={testingIds.has(webhook.id)}>- {testingId === webhook.id ? (+ {testingIds.has(webhook.id) ? (<Loader2 size={16} className="animate-spin" />) : (<Play size={16} />