fix(editor): Fix custom API call notice (#10227)

This commit is contained in:
Iván Ovejero 2024-07-30 17:41:26 +02:00 committed by GitHub
parent d719899223
commit 5b47c8b57b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import { createTestingPinia } from '@pinia/testing';
import { useNodeHelpers } from '@/composables/useNodeHelpers';
import { createTestNode } from '@/__tests__/mocks';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { CUSTOM_API_CALL_KEY } from '@/constants';
vi.mock('@/stores/workflows.store', () => ({
useWorkflowsStore: vi.fn(),
@ -17,6 +18,34 @@ describe('useNodeHelpers()', () => {
vi.clearAllMocks();
});
describe('isCustomApiCallSelected', () => {
test('should return `true` when resource includes `CUSTOM_API_CALL_KEY`', () => {
const nodeValues = {
parameters: { resource: CUSTOM_API_CALL_KEY },
};
expect(useNodeHelpers().isCustomApiCallSelected(nodeValues)).toBe(true);
});
test('should return `true` when operation includes `CUSTOM_API_CALL_KEY`', () => {
const nodeValues = {
parameters: {
operation: CUSTOM_API_CALL_KEY,
},
};
expect(useNodeHelpers().isCustomApiCallSelected(nodeValues)).toBe(true);
});
test('should return `false` when neither resource nor operation includes `CUSTOM_API_CALL_KEY`', () => {
const nodeValues = {
parameters: {
resource: 'users',
operation: 'get',
},
};
expect(useNodeHelpers().isCustomApiCallSelected(nodeValues)).toBe(false);
});
});
describe('getNodeInputData()', () => {
it('should return an empty array when node is null', () => {
const { getNodeInputData } = useNodeHelpers();

View file

@ -97,11 +97,13 @@ export function useNodeHelpers() {
if (!isObject(parameters)) return false;
if ('resource' in parameters && 'operation' in parameters) {
if ('resource' in parameters || 'operation' in parameters) {
const { resource, operation } = parameters;
if (!isString(resource) || !isString(operation)) return false;
return resource.includes(CUSTOM_API_CALL_KEY) || operation.includes(CUSTOM_API_CALL_KEY);
return (
(isString(resource) && resource.includes(CUSTOM_API_CALL_KEY)) ||
(isString(operation) && operation.includes(CUSTOM_API_CALL_KEY))
);
}
return false;