fix(Zendesk Trigger Node): Treat triggers with unverified actions as still in use on delete

This commit is contained in:
TemoSulava 2026-10-18 00:52:26 +04:00
parent 66b9d1e38e
commit ed558aed26
2 changed files with 32 additions and 8 deletions

View File

@ -429,14 +429,17 @@ export class ZendeskTrigger implements INodeType {
actions?: Array<{ field?: string; value?: unknown }>;
}> = await zendeskApiRequestAllItems.call(this, 'triggers', 'GET', '/triggers/active');
const webhookStillInUse = remainingTriggers.some((trigger) =>
trigger?.actions?.some(
(action) =>
action?.field === 'notification_webhook' &&
(Array.isArray(action.value)
? String(action.value[0]) === String(webhookData.targetId)
: String(action.value) === String(webhookData.targetId)),
),
const webhookStillInUse = remainingTriggers.some(
(trigger) =>
!trigger?.actions ||
!Array.isArray(trigger.actions) ||
trigger.actions.some(
(action) =>
action?.field === 'notification_webhook' &&
(Array.isArray(action.value)
? String(action.value[0]) === String(webhookData.targetId)
: String(action.value) === String(webhookData.targetId)),
),
);
if (!webhookStillInUse) {

View File

@ -246,6 +246,27 @@ describe('ZendeskTrigger Node', () => {
);
expect(deleteWebhookCalls).toHaveLength(0);
});
it('should treat triggers with missing or invalid actions as still in use to prevent accidental webhook deletion', async () => {
const apiRequestSpy = vi
.spyOn(GenericFunctions, 'zendeskApiRequest')
.mockResolvedValueOnce({});
vi.spyOn(GenericFunctions, 'zendeskApiRequestAllItems').mockResolvedValueOnce([
{
actions: undefined,
},
]);
const trigger = new ZendeskTrigger();
const result = await trigger.webhookMethods.default.delete.call(mockThis);
expect(result).toBe(true);
const deleteWebhookCalls = apiRequestSpy.mock.calls.filter(
([method, path]) =>
method === 'DELETE' && typeof path === 'string' && path.startsWith('/webhooks'),
);
expect(deleteWebhookCalls).toHaveLength(0);
});
});
describe('checkExists webhook method', () => {