From 6b46657412a1efff35be5083f0ff4c00f9b3e7f9 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 2 Jan 2025 10:43:34 -0500 Subject: [PATCH] fix(editor): Only ignore managed credentials in the HTTP node (#12417) --- .../src/components/NodeCredentials.test.ts | 67 ++++++++++++++++++- .../src/components/NodeCredentials.vue | 15 +++-- 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/packages/editor-ui/src/components/NodeCredentials.test.ts b/packages/editor-ui/src/components/NodeCredentials.test.ts index f5f816b0b1ed3..2839a75c031c3 100644 --- a/packages/editor-ui/src/components/NodeCredentials.test.ts +++ b/packages/editor-ui/src/components/NodeCredentials.test.ts @@ -7,6 +7,7 @@ import { createComponentRenderer } from '@/__tests__/render'; import { useCredentialsStore } from '@/stores/credentials.store'; import { mockedStore } from '@/__tests__/utils'; import type { INodeUi } from '@/Interface'; +import { useNDVStore } from '@/stores/ndv.store'; const httpNode: INodeUi = { parameters: { @@ -31,6 +32,25 @@ const httpNode: INodeUi = { issues: { parameters: { url: ['Parameter "URL" is required.'] } }, }; +const openAiNode: INodeUi = { + parameters: { + resource: 'text', + operation: 'message', + modelId: { __rl: true, mode: 'list', value: '' }, + messages: { values: [{ content: '', role: 'user' }] }, + simplify: true, + jsonOutput: false, + options: {}, + }, + type: '@n8n/n8n-nodes-langchain.openAi', + typeVersion: 1.8, + position: [440, 0], + id: '17241295-a277-4cdf-8c46-6c3f85b335e9', + name: 'OpenAI', + credentials: { openAiApi: { id: 'byDFnd7vN5GzMVD2', name: 'n8n free OpenAI API credits' } }, + issues: { parameters: { modelId: ['Parameter "Model" is required.'] } }, +}; + describe('NodeCredentials', () => { const defaultRenderOptions: RenderOptions = { pinia: createTestingPinia(), @@ -45,6 +65,9 @@ describe('NodeCredentials', () => { const renderComponent = createComponentRenderer(NodeCredentials, defaultRenderOptions); + const credentialsStore = mockedStore(useCredentialsStore); + const ndvStore = mockedStore(useNDVStore); + beforeAll(() => { credentialsStore.state.credentialTypes = { openAiApi: { @@ -80,9 +103,8 @@ describe('NodeCredentials', () => { }; }); - const credentialsStore = mockedStore(useCredentialsStore); - it('should display available credentials in the dropdown', async () => { + ndvStore.activeNode = httpNode; credentialsStore.state.credentials = { c8vqdPpPClh4TgIO: { id: 'c8vqdPpPClh4TgIO', @@ -103,7 +125,8 @@ describe('NodeCredentials', () => { expect(screen.queryByText('OpenAi account')).toBeInTheDocument(); }); - it('should ignore managed credentials in the dropdown', async () => { + it('should ignore managed credentials in the dropdown if active node is the HTTP node', async () => { + ndvStore.activeNode = httpNode; credentialsStore.state.credentials = { c8vqdPpPClh4TgIO: { id: 'c8vqdPpPClh4TgIO', @@ -132,4 +155,42 @@ describe('NodeCredentials', () => { expect(screen.queryByText('OpenAi account')).toBeInTheDocument(); expect(screen.queryByText('OpenAi account 2')).not.toBeInTheDocument(); }); + + it('should not ignored managed credentials in the dropdown if active node is not the HTTP node', async () => { + ndvStore.activeNode = openAiNode; + credentialsStore.state.credentials = { + c8vqdPpPClh4TgIO: { + id: 'c8vqdPpPClh4TgIO', + name: 'OpenAi account', + type: 'openAiApi', + isManaged: false, + createdAt: '', + updatedAt: '', + }, + SkXM3oUkQvvYS31c: { + id: 'c8vqdPpPClh4TgIO', + name: 'OpenAi account 2', + type: 'openAiApi', + isManaged: true, + createdAt: '', + updatedAt: '', + }, + }; + + renderComponent( + { + props: { + node: openAiNode, + }, + }, + { merge: true }, + ); + + const credentialsSelect = screen.getByTestId('node-credentials-select'); + + await fireEvent.click(credentialsSelect); + + expect(screen.queryByText('OpenAi account')).toBeInTheDocument(); + expect(screen.queryByText('OpenAi account 2')).toBeInTheDocument(); + }); }); diff --git a/packages/editor-ui/src/components/NodeCredentials.vue b/packages/editor-ui/src/components/NodeCredentials.vue index 1872db81913f0..8fe4b1515315e 100644 --- a/packages/editor-ui/src/components/NodeCredentials.vue +++ b/packages/editor-ui/src/components/NodeCredentials.vue @@ -1,9 +1,10 @@