mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-18 05:59:42 +02:00
fix(Zendesk Trigger Node): Treat triggers with unverified actions as still in use on delete
This commit is contained in:
parent
66b9d1e38e
commit
ed558aed26
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user